Hiding the selection in a CheckedListBox

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
 
C

ClayB

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.
 
J

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top