Updating Multiple DataGridViews

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a checkbox header that I want to add to a certain number of WinForm DataGridView controls.
Rather than adding the code to each form, is it possible to refer to it in a single class?
Thanks// Rather than setting ui_DetailsDataGridView I want
// to be able to set various datagridviews
private void AddDefaultColumns()
{
// add checkbox header -
Rectangle rect = this.ui_DetailsDataGridView.GetCellDisplayRectangle(0, -1, true);
// set checkbox header to center of header cell. +1 pixel to position correctly.
rect.X = 5;
rect.Y = 2;

CheckBox checkboxHeader = new CheckBox();
checkboxHeader.Name = "checkboxHeader";
checkboxHeader.Size = new Size(18, 18);
checkboxHeader.Location = rect.Location;
checkboxHeader.CheckedChanged += new EventHandler(checkboxHeader_CheckedChanged);
this.ui_DetailsDataGridView.Controls.Add(checkboxHeader);
}

void checkboxHeader_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.ui_DetailsDataGridView.RowCount; i++)
{
this.ui_DetailsDataGridView[this.approveCol.Index, i].Value = ((CheckBox)this.ui_DetailsDataGridView.Controls.Find("checkboxHeader", true)[0]).Checked;
}
this.ui_DetailsDataGridView.EndEdit();
}

View the full article
 
Back
Top