private void btnSelect_Click(object sender, EventArgs e) { //dataGridView1.CellMouseClick += dataGridView1_CellMouseClick; mCheckedListBox = new CheckedListBox(); mCheckedListBox.CheckOnClick = true; ToolStripControlHost mControlHost = new ToolStripControlHost(mCheckedListBox); mControlHost.Padding = Padding.Empty; mControlHost.Margin = Padding.Empty; mControlHost.AutoSize = false; mPopup = new ToolStripDropDown(); mPopup.Padding = Padding.Empty; mPopup.Items.Add(mControlHost); DoMyClickAction(((System.Windows.Forms.MouseEventArgs)(e)).X, ((System.Windows.Forms.MouseEventArgs)(e)).Y); mCheckedListBox.ItemCheck += new ItemCheckEventHandler(mCheckedListBox_ItemCheck); } private void DoMyClickAction(int x = 0, int y = 0) { mCheckedListBox.Items.Clear(); mCheckedListBox.Items.Add("Exceeding", blnExceedingClick); foreach (DataGridViewColumn c in dgvBreakAmount.Columns) { mCheckedListBox.Items.Add(c.HeaderText, c.Visible); } // mCheckedListBox.Items.Insert(0,"Exceeding"); int PreferredHeight = (mCheckedListBox.Items.Count * 16) + 7; mCheckedListBox.Height = (PreferredHeight < MaxHeight) ? PreferredHeight : MaxHeight; mCheckedListBox.Width = this.Width; mPopup.Show(dgvBreakAmount.PointToScreen(new Point(1000, 50))); } void mCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { if (e.Index != 0) dgvBreakAmount.Columns[e.Index - 1].Visible = (e.NewValue == CheckState.Checked); //mCheckedListBox.Items.Insert(0, "Exceeding"); if (e.Index == 0) { lblExceeding.Visible = (e.NewValue == CheckState.Checked); blnExceedingClick = e.NewValue == CheckState.Checked ? true : false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)