Why can I not click a small CheckedListBox? - c#

I have created a CheckedListBox control with 4 elements in C#. Multicolumn is set to true. As soon as I make the height of the control small enough to contain only a single row, I can no longer interact with the control with the cursor when I execute the program. If I make the height one unit (pixel?) larger, so that there are 2 columns of 2 rows, behavior returns to normal.
When the cursor cannot interact with the CheckedListBox, I can still tab to it, toggle between its elements with the arrow keys, and check/uncheck elements with the space bar. I just cannot use the cursor.

Looks like a bug to me... I'm experiencing the same thing occasionally. It happens when (1) the CheckedListBox is 1 row high, and (2) the items in it extend ANY past the right edge of the control. If the control is made a little wider, the mouse clicking works again. (You can test that theory by anchoring the CheckedListBox Left/Right and resizing the form. Now it works, now it don't.)

Seems like setting the width to be total column width + 4 also works.
There is a minimum width such that all columns are fully displayed that must be met before you can interact with it via mouse cursor.

Related

How to make ListBoxes in SplitContainers resize properly?

To reproduce this problem,
Create a new WinForms project
Using the WinForms designer, add a SplitContainer
Set its orientation to horizontal
Set its dock to fill
In each of the containers of the SplitContainer, add a ListBox
Set its dock to fill
Increase its font size so that the behaviour in question can be observed more clearly
Add a few items to the list boxes
After those steps, the designer should look like this:
Now run the program
Resize the containers in the SplitContainer
You should see that with some sizes of the upper container, there will be a space between the two list boxes (sorry for my bad mouse-writing).
For other sizes of the upper container, there is little to no space.
I hypothesized that this is because list boxes can't show "half an item" so it reduces its size to not show that half of an item. Is this true?
I have thought of the following solution:
Restricting the resizability of the split container so the user can only resize in "steps" where each step is equal to the height of one item in the list box.
However, I don't quite like this because when the item height is large, the user experience feels unnatural (at least to me).
How can I make it so that the list boxes resize properly (i.e. leaving no gaps)?
You can set the IntegralHeight property to false to achieve the desired effect.
https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.integralheight(v=vs.110).aspx
Gets or sets a value indicating whether the control should resize to avoid showing partial items.

How to display a collection so that all items are visible at once and are taking all available space?

I am currently developping a slideshow viewer that should be able to display all of its images in a grid like display. However, this display has the following requirements :
It should show all items without having to scroll;
It should be able to handle resizing well (like the Grid control does);
I am using a ListBox, with its ItemPanel set to either WrapPanel or UniformGrid, but they didn't met the requirements : Wrap Panel isn't resizing its items to fill all available space ; UniformGrid gets closer to the desired result, but still leaves an empty space at the end of the last row (ie it should only add a row when it can entirely fill it)
I am therefore looking into a way of setting an UniformGrid so that there's no "blank" left at the end.
As an example, let's say I have three items in my collection, and the actual room to fit them all on one row ; the grid will still creates another row for the third one.
I am also open to solutions for that problem involving other controls, as long as they have a similar behaviour on item resizing and still show all of their items at once.
Thanks
We finally decided to go with a simple wrap with a variable width between items and to just deal with having to scroll if there's too many items.

Continue on the right side when scrollbar is visible

In a checkedlistbox control in C# winforms I can add items into it, however the items will be placed under each other even when the height is smaller than the items combined.
My question is;
Can I "split" the checkedlistbox so you can see everything without having to scroll?
So when the left side is full, it will start on the other half of the checkedlistbox.
What you are looking for is CheckedListBox.MultiColumn property.

Custom Scrolling with ListView

I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.
Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.
What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.
I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!
I think I'd go for a different solution.
If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.
Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)
As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here

Only display complete items in a stackpanel

I have a slider which consists of grid of:
Scrollviewer
Stackpanel (the stackpanel is located inside the viewer)
The slider has 2 navigation buttons to browse trough the selected items.
But how can i only show complete items? Currently some buttons only get shown in half because there is no more space available. In the final version only 5 buttons should be shown at once. But if a certain event is fired more buttons will be visible for.
For example 1-5 are visible. If another button pops up only 2-6 should be visible.
The buttons inside the slider have to be created dynamically.
Does it make sense to stick with stack panel? Cause at the moment the buttons are static.
EDIT: When adding buttons dynamicly to the stackpanel how exactly does this work for already custom made buttons? I can add a normal button just fine but i wish to add the buttons already made below.
I believe the VirtualizingStackPanel (with virtualisation turned on as it is by default) can only perform item-based scrolling (as opposed to pixel-based scrolling). It might be worth trying swapping the StackPanel for a VirtualizingStackPanel to see if that fixes your problem.

Categories