Generating events to DataGridView Column controls

Description


Sometimes we need to generate events for the controls, which were in DataGridview.
Let us assume we have Checkbox and Combobox in a DataGridView(say dataGridView1)
Now I want to generate events to those columns.
Here is the way to generate events.
We can use EditingControlShowing event of datagridview


private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox comboCell = e.Control as ComboBox;
if (comboCell != null)
{
comboCell.DropDownStyle = ComboBoxStyle.DropDownList;
comboCell.SelectedIndexChanged -= new EventHandler(comboCell_SelectedIndexChanged);
comboCell.SelectedIndexChanged += new EventHandler(comboCell_SelectedIndexChanged);
}


CheckBox ck = e.Control as CheckBox;
if (ck != null)
{
ck.CheckedChanged += new EventHandler(ck_CheckedChanged);
}
}


Implement your functionality in that events


Related Articles

Insert, update and delete data using DataGridView

You can use DataGridView to fetch all the data from SQL server 2005 and then perform insert, update and delete directly in gridview then make save changes all at once.(in window application(C#)).

More articles: DataGridView

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: