Hiding the selection in a CheckedListBox

  • Thread starter Thread starter Jared
  • Start date Start date
J

Jared

Is it possible to do away with the "selected" appearance of an item in
a CheckedListBox (v1.1)? When I click an item, its background turns
blue and its text turns white. I want the checkbox to toggle (which
it currently does), but I don't want the list item to appear
"selected".

TIA
Jared
 
You can try handling SelectedIndexChanged event and clearing the
selection there. This got rid of the selection after the click for me,
but there still was a temporary selection that flashed as you click
the checkbox. This code just removes it immediately.

private void checkedListBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
int index = checkedListBox1.SelectedIndex;
if(index > -1)
{
checkedListBox1.SetSelected(index, false);
checkedListBox1.SetItemChecked(index, !
checkedListBox1.CheckedIndices.Contains(index));
}
}

================
Clay Burch
Syncfusion, Inc.
 
You can try handling SelectedIndexChanged event and clearing the
selection there. This got rid of the selection after the click for me,
but there still was a temporary selection that flashed as you click
the checkbox. This code just removes it immediately.

private void checkedListBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
int index = checkedListBox1.SelectedIndex;
if(index > -1)
{
checkedListBox1.SetSelected(index, false);
checkedListBox1.SetItemChecked(index, !
checkedListBox1.CheckedIndices.Contains(index));
}

}

================
Clay Burch
Syncfusion, Inc.

Thanks Clay, that works pretty well. I had to eliminate
SetItemChecked() or the checkbox would never change state. Looks like
SetSelected() was exactly what I needed.

Cheers!
Jared
 
Back
Top