M. os.i
M. os.i

Reputation: 153

How to fire C# DataGridView SelectionChanged event programmatically?

I have a problem in firing DataGridView SelectionChanged using code, i'm working on Windows forms unsing C# on Visual Studio 2013.

I use this solution :

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{    
/* Code here ...  */
}

and fire it using a button click like this :

 private void button1_Click(object sender, EventArgs e)     
 {
 ...
 dataGridView1_SelectionChanged(sender,e);
 ...
 }

Is this the right way to do this ?

Upvotes: 1

Views: 2218

Answers (1)

Z.R.T.
Z.R.T.

Reputation: 1603

very simple , the following will fire dataGridView1_SelectionChanged event handler

private void button1_Click(object sender, EventArgs e)
{
    dataGridView1.Rows['row_index'].Selected = true;
}

Upvotes: 0

Related Questions