0

How to create button click function for dynamically created button column.

DataGridViewButtonColumn select = new DataGridViewButtonColumn();
select.Text = "Details";
select.HeaderText = "Details";
select.Name = "Select";
dataGridView5.Columns.Add(select);

This is the code I have used to create button dynamically in my datagridview.

Can you give an example on how to write button_click function for onclick of button.

3 Answers 3

2

use the CellContentClick-Event

Example:

 private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.CellContentClick += new DataGridViewCellEventHandler(dataGridView1_CellContentClick);

        DataGridViewButtonColumn select = new DataGridViewButtonColumn();
        select.Text = "Details";
        select.HeaderText = "Details";
        select.Name = "Select";
        dataGridView1.Columns.Add(select);
    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == dataGridView1.Columns["Select"].Index)
        {
            MessageBox.Show(String.Format("Clicked! Row: {0}", e.RowIndex));
        }
    }

CellContentClick on MSDN

Sign up to request clarification or add additional context in comments.

Comments

1

You may handle either DataGridView.CellClick or DataGridView.CellContentClick event.

Comments

0

Hello you can associate with CellClick event

http://msdn.microsoft.com/fr-fr/libr...0s(VS.80).aspx

Or with this exemple very interessant

http://www.c-sharpcorner.com/UploadFile/9f4ff8/datagridviewlinkcolumn-datagridviewbuttoncolumn-in-C-Sharp/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.