tags:

views:

1015

answers:

1

When an item is clicked in the checkedlistbox, it gets highlighted. How can I prevent this highlighting effect?

I can hook into the SelectedIndexChanged event and clear the selection, but the highlighting still happens and you see a blip. In fact, if you hold down the mouse click, never releasing it after you clicked on the checkbox area, the selection remains highlighted until you release the mouse button. I basically want to get rid of this highlighting effect altogether.

+3  A: 

this will do it apart from you still get the dotted line bit.

this.checkedListBox1.SelectionMode = System.Windows.Forms.SelectionMode.None;

although now you can't click the check boxes... so you'll have to do something like so:

  private void checkedListBox1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < checkedListBox1.Items.Count; i++)
  {


          if (checkedListBox1.GetItemRectangle(i).Contains(checkedListBox1.PointToClient(MousePosition)))
          {
              switch (checkedListBox1.GetItemCheckState(i))
              {
                  case CheckState.Checked:
                      checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
                      break;
                  case CheckState.Indeterminate:
                  case CheckState.Unchecked:
                      checkedListBox1.SetItemCheckState(i, CheckState.Checked);
                       break;
              } 

          }

  }
    }

if all that isn't what your after.. you can always just make your own one. its a fairly simple control.

Hath
Seems like it would be more efficient to use checkedListBox1.IndexFromPoint(e.x, e.y) in the MouseDown handler, instead of looping through the GetItemRectangle results.
Eyal