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

2.5k views Asked by At

When I develop ASP .NET Web Applications, I use the following code to show Update and 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 and Cancel. And on cell click event of DataGridView, Edit column will be hidden and Update and Cancel Column will be displayed.

Another solution is to use 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. Any help will be very much appreciated.

1

There are 1 answers

0
Jeetu On

I think you can do like this & perform operations as you want :

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

        }