我将DataGridView的DataSource设置为DataTable。然后我向DataGridView添加了2个按钮列。 DataGridView在表单上看起来很好,但是,当我在索引1和6处插入按钮时,DataGridView将其点击事件作为索引0和1返回。这似乎是通过添加除DataSource之外的按钮来实现的。
有关如何解决此问题的任何建议?
DataTable dataTable= someMethod();
DataGridView.DataSource = dataTable;
// Add a button to the DataGridView at the specified position
DataGridViewButtonColumn btnEdit = new DataGridViewButtonColumn();
btnEdit.Name = "btnEdit";
btnEdit.Text = "Edit";
btnEdit.HeaderText = "Edit Quantity";
btnEdit.UseColumnTextForButtonValue = true;
DataGridView.Columns.Insert(1, btnEdit);
DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
btnDelete.Name = "btnDelete";
btnDelete.Text = "Delete";
btnDelete.HeaderText = "Delete";
btnDelete.UseColumnTextForButtonValue = true;
DataGridView.Columns.Insert(6, btnDelete);