本文介绍了如何将基于索引的项添加到Mcheckedlistbox(或)Mpopup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
}
例如:mCheckedListBox.Items.Add(Exceeding,blnExceedingClick);我需要添加更多这样的项目,如果我添加超过1,任何一个都可以。给我一个解决方案。 thanku
For ex: mCheckedListBox.Items.Add("Exceeding", blnExceedingClick); i need to add more items like this, if i added more than 1,either one will work. Give me a solution. thanku
推荐答案
这篇关于如何将基于索引的项添加到Mcheckedlistbox(或)Mpopup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!