You must Sign In to post a response.
  • Category: .NET

    Adding button to datagridview in windows application

    Dear friends,

    I want to add button in each row of column of already bounded datagridview and add event to it (in VS 2005, wndows application). I have searched a lot but was unable to find a working solution.
  • #169971
    Hi,

    You can use GridviewButtonColumn for that. See this code...
    private void Form1_Load(object sender, EventArgs e)
    {
    DataGridViewButtonColumn dgBtnCol = new DataGridViewButtonColumn();
    dataGridView1.Columns.Add(dgBtnCol);//Add one column dynamically
    }

    Then after in cell click event .....

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
    if (e.ColumnIndex == (dataGridView1.Columns.Count-1))//check whether is it button column or not.....
    {
    MessageBox.Show("Success");
    }
    }


    Regards,
    Ronak Thakkar


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.