0

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#

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by nick.crane
0

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;
            }
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.