Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Updating Multiple DataGridViews

$
0
0

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();
        }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>