版本:Version : 2018J v2
Demo代码:
新建C#窗体工程(Framework4.0以上)
窗体中加入以下代码(引入C1.Win.C1TrueDBGrid命名空间)
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- C1TrueDBGrid tdb = new C1TrueDBGrid();
- tdb.Location = new Point(10, 10);
- tdb.Size = new Size(300, 200);
- tdb.FlatStyle = FlatModeEnum.Standard;
- tdb.RowHeight = 20;
- tdb.Splits[0].ColumnCaptionHeight = 20;
- Controls.Add(tdb);
- DataTable dt = new DataTable();
- dt.Columns.Add("button").DefaultValue="…";
- dt.Columns.Add("input");
- dt.Rows.Add("…", "");
- dt.Rows.Add("…", "");
- dt.Rows.Add("…", "");
- tdb.Columns.Clear();
- C1DataColumn col;
- C1DisplayColumn dispCol;
- int colIndex;
- col = new C1DataColumn();
- colIndex= tdb.Columns.Add(col);
- col.DataField = "button";
- col.Caption = "button";
- dispCol = tdb.Splits[0].DisplayColumns[colIndex];
- dispCol.ButtonText = true;
- dispCol.ButtonAlways = true;
- dispCol.Visible = true;
- col = new C1DataColumn();
- colIndex = tdb.Columns.Add(col);
- col.DataField = "input";
- col.Caption = "input";
- dispCol = tdb.Splits[0].DisplayColumns[colIndex];
- dispCol.Visible = true;
- tdb.SetDataBinding(dt, "", true);
- tdb.ButtonClick += Tdb_ButtonClick;
- }
- private void Tdb_ButtonClick(object sender, ColEventArgs e)
- {
- if (e.ColIndex == 0)
- ((C1TrueDBGrid)sender).Col = 1;
- }
复制代码 |