views:

1005

answers:

2

I've got a Checkedlistbox, which is 3 rows high, and large enough to display about 5 elements.

As long as I've got less than 15 elements, everything runs fine. However, if I add a sixteenth element, the checkedlistbox displays an horizontal scrollbar which takes 2 item rows, which means all the Items are now on only one row.

Worse, if I remove the extra item, the horizontal scrollbar stays in place.

I've tried using :

mycheckedlistbox.HorizontalScrollbar = false;
mycheckedlistbox.ScrollAlwaysVisible = false;

but this doesn't seem to have any effect.

I use the multicolumn=true mode, which seems to cause this misbehaviour

Is there a way to prevent the control from displaying an horizontal scrollbar, and use a vertical scrollbar instead?

I've found someone with a similar question on msdn forums, but it seems he didn't get an anwser.

+1  A: 

The scrollbar makes the layout of the items bi-stable. You can get the scrollbar to disappear by whacking it on the head:

  checkedListBox1.MultiColumn = false;
  checkedListBox1.MultiColumn = true;

That forces WF to recreate the control handle, the flicker might be barely noticeable. Yes, a vertical scrollbar is possible but you'll have to give up on MultiColumn.

Hans Passant
+1  A: 

Well, judging from the answers there, and from the few test I ran, this does seem sort of impossible, but at the same time, I think you're trying to defeat the purpose. If I were in you're shoes, I'd use a DataGridView with no grid lines and one that can't be editable. You have much more control over what's going on in the grid, and you can customize it MUCH more than a CheckedListBox. You can have the same effect as you can have DataGridViewCheckBoxColumns there as well.

(If you need a code sample, post in the comments, and I'll whip up a quick sample.)

BFree