DataGridView's SelectionChange event firing twice on DataBinding even after removing event binding

Posted by Shantanu Gupta on Stack Overflow See other posts from Stack Overflow or by Shantanu Gupta
Published on 2010-06-03T15:33:35Z Indexed on 2010/06/03 16:14 UTC
Read the original article Hit count: 568

Filed under:
|
|
|
|

This Code triggers selection change event twice. how can I prevent it ? Currently i m using a flag or focused property to prevent this. But what is the actual way ?

I am using it on winfoms

EDIT

My Mistake in writing Question, here is the correct code that i wanted to ask

private void frmGuestInfo_Load(object sender, EventArgs e)
{
this.dgvGuestInfo.SelectionChanged -= new System.EventHandler(this.dgvGuestInfo_SelectionChanged);
dgvGuestInfo.DataSource=dsFillControls.Tables["tblName"];
this.dgvGuestInfo.SelectionChanged += new System.EventHandler(this.dgvGuestInfo_SelectionChanged);
}

private void dgvGuestInfo_SelectionChanged(object sender, EventArgs e)
{
//this function is raised twice, i was expecting that this will not be raised 
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET