I am having two problems with my checklistbox select items.
1. When I check individual box, I have to click twice to get it checked.
2. Altough all the checkboxes are checked after I click "select all", I get the values of the first and second selected items. After that I get every other value of the items selected.
Here are my codes. I don't know what is wrong.
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
SelectClicked = true;
if (chkSelectAll.Checked)
{
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
EmployeeNameList.SetItemChecked(i, true);
}
chkDeselectAll.Checked = false;
}
SelectClicked = false;
}
private void chkDeselectAll_CheckedChanged(object sender, EventArgs e)
{
SelectClicked = true;
if (chkDeselectAll.Checked)
{
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
EmployeeNameList.SetItemChecked(i, false);
}
chkSelectAll.Checked = false;
}
SelectClicked = false;
}
private void EmployeeNameList_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (SelectClicked) return;
//manage chkSelectAll
bool checkedValue = true;
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
if (i == e.Index)
{
if (e.NewValue != CheckState.Checked)
{
checkedValue = false;
break;
}
}
else
{
if (!EmployeeNameList.GetItemChecked(i))
{
checkedValue = false;
break;
}
}
}
chkSelectAll.Checked = checkedValue;
//manage chkDeselectAll
checkedValue = true;
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
if (i == e.Index)
{
if (e.NewValue == CheckState.Checked)
{
checkedValue = false;
break;
}
}
else
{
if (EmployeeNameList.GetItemChecked(i))
{
checkedValue = false;
break;
}
}
}
chkDeselectAll.Checked = checkedValue;
}
Thanks a lot.
1. When I check individual box, I have to click twice to get it checked.
2. Altough all the checkboxes are checked after I click "select all", I get the values of the first and second selected items. After that I get every other value of the items selected.
Here are my codes. I don't know what is wrong.
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
SelectClicked = true;
if (chkSelectAll.Checked)
{
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
EmployeeNameList.SetItemChecked(i, true);
}
chkDeselectAll.Checked = false;
}
SelectClicked = false;
}
private void chkDeselectAll_CheckedChanged(object sender, EventArgs e)
{
SelectClicked = true;
if (chkDeselectAll.Checked)
{
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
EmployeeNameList.SetItemChecked(i, false);
}
chkSelectAll.Checked = false;
}
SelectClicked = false;
}
private void EmployeeNameList_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (SelectClicked) return;
//manage chkSelectAll
bool checkedValue = true;
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
if (i == e.Index)
{
if (e.NewValue != CheckState.Checked)
{
checkedValue = false;
break;
}
}
else
{
if (!EmployeeNameList.GetItemChecked(i))
{
checkedValue = false;
break;
}
}
}
chkSelectAll.Checked = checkedValue;
//manage chkDeselectAll
checkedValue = true;
for (int i = 0; i < EmployeeNameList.Items.Count; i++)
{
if (i == e.Index)
{
if (e.NewValue == CheckState.Checked)
{
checkedValue = false;
break;
}
}
else
{
if (EmployeeNameList.GetItemChecked(i))
{
checkedValue = false;
break;
}
}
}
chkDeselectAll.Checked = checkedValue;
}
Thanks a lot.