i have one check list box which have check box's like admin,physisian,Nurs<practicenerNurse,frontdesk etc
and there is one another check box called "Clinical access"
i want to check any of chechbox in my check list box accept Admin then clinical access check box checked automaticaly have write folowing code but it also check for admin

private void Modules_ItemCheck(object sender, ItemCheckEventArgs e)
{
 if (e.NewValue == CheckState.Checked)
            {
               
                ClinicalAccess.Checked = true;
                ClinicalAccess.Enabled = false;
            }
            else
            {
                int i = Convert.ToInt32(Modules.CheckedItems.Count);
                if (i > 1)
                {
                    ClinicalAccess.Checked = true;
                    ClinicalAccess.Enabled = false;
                }
                else
                {
                    ClinicalAccess.Checked = false;
                    ClinicalAccess.Enabled = true;
                }
            }
}

i am working on Windows application with C#

I have tried doing similar things with the CheckedListBox before.
The information on the checked items is not yet updated when the ItemCheck event fires.
This just makes all the logic very difficult.
I gave up trying doing my logic in the ItemCheck event.

The solution I came up with is to call an update method asynchronously in the ItemCheck event.
When it executes the collections on the CheckedListBox are up to date.

private void Modules_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            this.BeginInvoke(new UpdateDelegate(UpdateClinicalAccess));
        }

        delegate void UpdateDelegate();

        private void UpdateClinicalAccess()
        {
            int adminIndex = Modules.Items.IndexOf("Admin");
            bool adminChecked =
                Modules.CheckedIndices.Contains(adminIndex);

            if ((Modules.CheckedItems.Count > 0)
               && !adminChecked)
            {
                ClinicalAccess.Checked = true;
                ClinicalAccess.Enabled = false;
            }
            else
            {
                ClinicalAccess.Checked = false;
                ClinicalAccess.Enabled = true;
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.