如何通过数据表绑定Button列。并将Datatable绑定到Datagridview

时间:2017-05-19 06:36:28

标签: c# datagridview datatable

我想知道

  

如何通过DataTable绑定按钮列并将其绑定   DataTableDatagridview

我在这里使用Checkbox 选择我想要使用Button替换它的行。有没有可能的方法?

Datatabe初始化: -

 orderTable = new DataTable();
 orderTable.Rows.Clear();
 orderTable.Clear();
 orderTable.Columns.Add("Select", typeof(bool));
 orderTable.Columns.Add("Time");
 orderTable.Columns.Add("Date");
 orderTable.Columns.Add("Order#");
 orderTable.Columns.Add("CustName");
 orderTable.Columns.Add("Product");
 orderTable.Columns.Add("Imagepath");
 orderTable.Columns.Add("datetime");

绑定行: -

 DataRow Drorder = orderTable.NewRow();
 Drorder["Select"] = false;
 Drorder["Time"] = time;
 Drorder["Date"] = date;
 Drorder["Order#"] = ordernumber;
 Drorder["CustName"] = Name;
 Drorder["Product"] = prodcutname;
 Drorder["Imagepath"] = pathf;
 Drorder["datetime"] = folderDatetime;
 orderTable.Rows.Add(Drorder);
 Orders.DataSource = orderTable;

以下方法给出错误..

  

指定的演员无效

DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Test Button";
btn.Text = "Test Btn";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;`    

0 个答案:

没有答案