当我开发ASP .NET Web应用程序时,当用户单击DataGridView列中的Update
按钮时,我使用以下代码显示Cancel
和Edit
按钮。
<asp:EditCommandColumn EditText="Edit"
ButtonType="LinkButton"
UpdateText="Update"
CancelText="Cancel"
HeaderText="Update"/>
有没有办法在Windows窗体中执行此操作?我现在计划做的是添加三个DataGridViewButtonColumn
Edit
Update
,Cancel
和Edit
。在DataGridView的单元格点击事件中,将隐藏Update
列,并显示Cancel
和DataGridViewLinkCell
列。
另一种解决方案是使用{{1}}并在单击单元格后更改列的值。 示例:Insert, Update & Delete Table from DataGridView in C#.Net
关于DataGridView选择/插入/更新/删除命令的SO问题有很多问题。但我想知道哪种方法适合在这种情况下使用。任何帮助将非常感谢。
答案 0 :(得分:0)
我认为你可以这样做&amp;根据需要执行操作:
private void Form1_Load(object sender, EventArgs e)
{
displayDataGridView();
DataGridViewButtonColumn EditBtn = new DataGridViewButtonColumn();
EditBtn.HeaderText = "Edit";
EditBtn.Text = "Edit";
EditBtn.Name = "EditBtn";
EditBtn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(EditBtn);
DataGridViewButtonColumn DeleteBtn = new DataGridViewButtonColumn();
DeleteBtn.HeaderText = "Delete";
DeleteBtn.Name = "DeleteBtn";
DeleteBtn.Text = "Delete";
DeleteBtn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(DeleteBtn);
}