设置某一列为只读
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.ActivateOnly;选择后的缺省前景和背景色
this.ultraGrid1.DisplayLayout.DefaultSelectedBackColor = Color.Azure;this.ultraGrid1.DisplayLayout.DefaultSelectedForeColor = Color.YellowGreen;使用dataset绑定。
检索数据,建立table之间的关系。ultraGrid自动建立层次式展示方式。DataSet data = new DataSet();SqlDataAdapter da = new SqlDataAdapter("select * from customers", cnnstring);da.Fill(data, "Customers");da = new SqlDataAdapter("select * from pdctorders", cnnstring);da.Fill(data, "PdctOrders");DataRelation mydr = new DataRelation("Customers_PdctOrders", data.Tables["Customers"].Columns["CustID"], data.Tables["pdctorders"].Columns["CustID"], false);data.Relations.Add(mydr);da = new SqlDataAdapter("select * from SaleContracts", cnnstring);
da.Fill(data, "SaleContracts");DataRelation mydr2 = new DataRelation("Customers_SaleContracts", data.Tables["Customers"].Columns["CustID"], data.Tables["SaleContracts"].Columns["CustID"],false);
data.Relations.Add(mydr2);this.ultraGrid1.DataSource = data;
1)系统自动根据源数据的类型选择合适的控件展示,如日历控件、单选框等;2)缺省都是左对齐的;3)所有数据原样显示,没有格式化的。如何根据数据类型自动设置列,如格式、对齐等?
foreach (UltraGridBand ugb in this.ultraGrid1.DisplayLayout.Bands) { foreach (UltraGridColumn ugc in ugb.Columns) { if (ugc.DataType == Type.GetType("System.Int8") || ugc.DataType == Type.GetType("System.Int16") || ugc.DataType == Type.GetType("System.Int32") || ugc.DataType == Type.GetType("System.Int64")) { ugc.Format = "#,#"; ugc.CellAppearance.TextHAlign = HAlign.Right; } else if (ugc.DataType == Type.GetType("System.Single") || ugc.DataType == Type.GetType("System.Double")) { ugc.Format = "#,0.00"; ugc.CellAppearance.TextHAlign = HAlign.Right; } else if (ugc.DataType == Type.GetType("System.DateTime")) { ugc.Format = "yyyy/MM/dd"; ugc.MaskInput = "yyyy/mm/dd"; } } }