How to > DataGridView > Technical Logic > Part 2

.NET programming topics
Post Reply
Neofriend
Captain
Captain
Posts: 103
Joined: Wed Dec 23, 2009 3:37 pm
Location: Pakistan

How to > DataGridView > Technical Logic > Part 2

Post by Neofriend » Wed Jan 06, 2010 10:22 pm

A very specific question here. Would like to make use of DoubleClick event, when someone clicks the empty cell before every row.

Made the method and assigned it to DoubleClick event. It works too.

Now am loading data from the database in the DataGridView; how can I get the value of Cell[0] of respective row on which I double clicked. I'd like to get the int value there in Cell[0] so I can show the detailed form of that entry.

With this, yes, my question is also about kindly sharing how the value transferring works between methods, forms and such helpful examples.

Thank you.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to > DataGridView > Technical Logic > Part 2

Post by Neo » Thu Jan 07, 2010 1:53 am

Code: Select all

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
     MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString());
}
Neofriend
Captain
Captain
Posts: 103
Joined: Wed Dec 23, 2009 3:37 pm
Location: Pakistan

Re: How to > DataGridView > Technical Logic > Part 2

Post by Neofriend » Thu Jan 07, 2010 1:59 am

How can we pass this value to a new form?

I have two ideas, not sure if they are correct.

1. To instantiate the new form and assigning this value to a public variable to access there.
2. Assign the value to an static variable.

Are they correct? Any other suitable options? Most preferable please?
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to > DataGridView > Technical Logic > Part 2

Post by Neo » Thu Jan 07, 2010 2:42 am

The controls on a form are private, visible only for that form by design. So better to store it in a public variable.
Post Reply

Return to “.NET Programming”