Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;
            }

        }

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
Posted
Comments
Thava Rajan 21-Sep-15 1:46am    
please let be more clear?
is the items are not added?
or do you want to check all the items?
Sathish km 21-Sep-15 4:53am    
ITEMS ARE ADDED, NOT INDEX BASED
Thava Rajan 23-Sep-15 1:55am    
you are added the items one by one, so it has an index obviously
watch your itemcheck event, you used the index there, also it seems some thing you need to work there also?
hope you understand
Thava Rajan 23-Sep-15 1:55am    
what are you try to do?

show some work out that is not working for you?


1 solution

you need to use the checkedlistbox's method setitemchecked[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900