DotNetBar 中 SuperGridControl 加载数据、获取数据、设置样式
1.加载数据
构建列
//加载列 GridColumn gd = new GridColumn(); gd.Name = "第1"; gd.HeaderText = "第1"; superGridControl1.PrimaryGrid.Columns.Add(gd); gd = new GridColumn(); gd.Name = "第2"; gd.HeaderText = "第2"; superGridControl1.PrimaryGrid.Columns.Add(gd); gd = new GridColumn(); gd.Name = "第3"; gd.HeaderText = "第3"; superGridControl1.PrimaryGrid.Columns.Add(gd);
加载行
GridRow Dfr = superGridControl1.PrimaryGrid.NewRow(); Dfr[0].Value = "1"; Dfr[1].Value = "2"; Dfr[2].Value = "3"; superGridControl1.PrimaryGrid.Rows.Add(Dfr); Dfr = superGridControl1.PrimaryGrid.NewRow(); Dfr[0].Value = "2"; Dfr[1].Value = "3"; Dfr[2].Value = "4"; superGridControl1.PrimaryGrid.Rows.Add(Dfr); Dfr = superGridControl1.PrimaryGrid.NewRow(); Dfr[0].Value = "3"; superGridControl1.PrimaryGrid.Rows.Add(Dfr); Dfr = superGridControl1.PrimaryGrid.NewRow(); Dfr[0].Value = "4"; superGridControl1.PrimaryGrid.Rows.Add(Dfr); Dfr = superGridControl1.PrimaryGrid.NewRow(); Dfr[0].Value = "5"; superGridControl1.PrimaryGrid.Rows.Add(Dfr);
2.获取数据
// 获取某一行的信息 GridRow DG = this.superGridControl1.PrimaryGrid.Rows[0] as GridRow; //设置某一单元的背景颜色 DG[0].CellStyles.Default.Background.Color1 = Color.Red; //获取某一单元格的值 string Text = DG[0].values.tostring();
//获取选中单元整行数据 SelectedElementCollection col = this.superGridControl1.PrimaryGrid.GetSelectedRows(); //int /*/*sss*/*/ =int .Parse( superGridControl1.PrimaryGrid.SelectedCells as string ); if (col.Count > 0) { MessageBox.Show(col[0].ToString()); }
3.设置样式
this.superGridControl1.PrimaryGrid.Filter.Visible = false; /控制表格只能选中单行 superGridControl1.PrimaryGrid.MultiSelect = false; superGridControl1.PrimaryGrid.InitialSelection = RelativeSelection.Row; //只能选中一个单元格,而不是一行单元格 superGridControl1.PrimaryGrid.SelectionGranularity =SelectionGranularity.Row; //是否显示序列号 superGridControl1.PrimaryGrid.ShowRowHeaders = false; //自动填满表格 superGridControl1.PrimaryGrid.ColumnAutoSizeMode = ColumnAutoSizeMode.Fill; //允许单元格拖动成为集合组 superGridControl1.PrimaryGrid.ColumnHeader.AllowSelection = true; superGridControl1.PrimaryGrid.GroupByRow.Visible = false; GridPanel panel = superGridControl1.PrimaryGrid; //设置表格自动展开 panel.AutoExpandSetGroup = true; panel.SetGroup(panel.Columns["工作单位"]); //设置表格中文字的位置居中 superGridControl1.PrimaryGrid.DefaultVisualStyles.CellStyles.Default.Alignment= DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;
加载图片
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); //转换成二进制 byte[] imabytesin = br.ReadBytes((int)fs.Length); Image img = reph(imabytesin);//将二进制数组转换成Image类型 this.imageList1.Images.Add("1", img); this.imageList1.Images.Add("2", img); this.imageList1.Images.Add("3", img);//保存到imagelist中 InitializeGrid(); private void InitializeGrid() { GridPanel panel = superGridControl1.PrimaryGrid; //指定显示的列 GridColumn column = panel.Columns[0]; column.EditorType = typeof(MyGridImageEditControl); column.EditorParams = new object[] { imageList1, ImageSizeMode.Zoom }; }
private class MyGridImageEditControl : GridImageEditControl
{
public MyGridImageEditControl(ImageList imageList, ImageSizeMode sizeMode)
{
ImageList = imageList;
ImageSizeMode = sizeMode;
}
}
加载combox下拉
var girdc = superGridControl1.PrimaryGrid.Columns[1]; var list = new object[] { "销售部", "采购部" }; girdc.EditorType = typeof(MyComboBox); girdc.EditorParams = new object[] { list };
实例图片
百度的搬运工,亲测