C# .NET - button click event in datagridviewbutton column

Asked By vigneshvari - on 03-May-09 01:12 AM

can any on help me to generate a button event when datagridview button column is clicked.when click the button form should be navigated to another form taking an id value(student id or employee id)

thanks

vigneshvari

Santhosh N replied to vigneshvari - on 03-May-09 02:10 AM
You can handle this event in the CellContentClick event of the DataGridView and capturing the column index as shown below

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex ==1) //Assuming the button column as second column, if not can change the index
            {
                //check if anything needs to be validated here
                Form1 f = new Form1();
                f.navId = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                f.Show();

            }
        }

In the above code, assign the value of the id from using this statement
f.navId = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

For this to work, just declare a public variable in the target form (navId in this eg)

thanks for your reply

vigneshvari - replied to Santhosh N on 03-May-09 08:56 AM
end of post

thank for reply

Asked By vigneshvari - on 03-May-09 08:57 AM
end of post
Welcome...
Santhosh N replied to vigneshvari - on 03-May-09 08:57 AM
end of post
example for datagridview
Asked By vigneshvari - on 04-May-09 02:54 AM
end of post
Ali replied to Santhosh N on 28-Nov-10 04:24 AM
Thanks
Mahmudul hasan replied to vigneshvari - on 16-Jul-11 05:00 AM
it helped me a lot...thank you