Windows Forms - How to display Update/Cancel Button in DataGridViewButtonColumn?

When I develop ASP .NET Web Applications, I use the following code to show Update а также Cancel buttons when a user clicks on Edit button inside DataGridView Column.

<asp:EditCommandColumn EditText="Edit" 
             ButtonType="LinkButton" 
             UpdateText="Update" 
             CancelText="Cancel" 
             HeaderText="Update"/>

Is there any way to do it in Windows Forms? What I have planned to do now is I will add three DataGridViewButtonColumns Edit, Update а также Cancel, And on cell click event of DataGridView, Edit column will be hidden and Update а также Cancel Column will be displayed.

Другое решение заключается в использовании DataGridViewLinkCell and change the value of the column after clicking on the cell. Example: Insert, Update & Delete Table from DataGridView in C#.Net

There are a lot of questions on SO asking about DataGridView Select/Insert/Update/Delete Commands. But I'd like to know which will be the suitable method to use in this situation. Любая помощь будет очень ценится.

1 ответ

Я думаю, что вы можете делать это и выполнять операции, как вы хотите:

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);  

        }
Другие вопросы по тегам