I have a combobox, but it only shows scrollbar when there is more than 30 items. It causes the combobox becomes too long - can't blame it, but sometimes, people think it's ugly. So Is there a way to limit the max visible items on combobox - like I have 60 items, and the combo box shows only 10 item at a time, use scrollbar to see more items.
Use CBS_DISABLENOSCROLL to always show the scrollbar.
Define the dropdown Width smaller in you dialog resource.
Or Adjust the height as you want inside the program.
Intercept the CBN_DROPDOWN notification
Calculate the size you want.
Call GetComboBoxInfo to get hwndList
Use SetWindowPos with SWP_NOMOVE and SWP_NOZORDER to change the size
Is there a way to limit the max visible items on combobox
Layout your combobox with the resource editor, and set the cursor to where it is marked in red:
It then immediately changes layout to this:
And this is how you set the height of a combobox list.
Related
I have a ListView which is explicitly populated (no binding) with ListViewItems.
Most of the items need to Visible and others should remain collapsed. All the items are of the same height.
The problem is if I have 100 items and first 60 are visible and the bottom 40 are in collapsed state, the scroll bar's height become something based on the assumption that all the 100 items are in visible state and the scroll bar's height becomes less than what it should be. But when I scroll down to 60, it realizes that the rest 40 are in collapsed state and therefore increases the scroll bar's height to make it appropriate for 60 items in the list view.
I initially thought it may be because of virtualization. But I dod not have any binding of data to the list view. I also tried to set the height of the items to 0 that need to be in collapsed state which did not give me the desired result.
What I need is, if there are 60 items visible and 40 collapsed then the scroll bar's height should be based on only 60 items in the list view and should remain constant.
Is it possible to achieve?
I had exactly the same problem, and the answer can be found here: Listbox scrollbar thumb changes size when content is variable height
Shortly, add ScrollViewer.CanContentScroll="False" on the ListBox and the scrollbar will have constant height regardless on the number of collapsed items.
By the way, I am aware that the question is almost 2 years old, however I'd like to leave it for future reference.
I'm not sure what made you decide it wasn't virtualization, as that is what it must be. Try turning off virtualization:
<ListView VirtualizingStackPanel.IsVirtualizing="False" ...
I realized something annoying when using a data grid view control. When I try to set the cell's height by setting the RowTemplate height property to fit more records on the grid, the vertical scroll bar stops acting nicely and the grid doesnt display all the records (it only shows the records that fit on the available space plus one extra record!) until you resize the columns or something like that! But if I set the AutoSizeRowsMod property to AllCells the grid displays all the records, however the cell's height is now too big for me!
Is there a way to control the cell's height and still show all the records on the DGV? Does it even make sense that it's behaving this way?
Thanks
I've got a Silverlight user control that contains a datagrid. The datagrid is bound to an ObservableCollection. The user control is displayed in a popup window that I show in response to some event in another control
There are about 80 objects in the collection, and I've set a fixed height of 400 on the datagrid, so only about 20 items can be shown at one time, and the vertical scrollbar should be shown, with a thumb size occupying about 1/4th of the control height.
However, what's actually happening is that the scrollbar occupies almost the whole control height; maybe 95% of it. The datagrid displays the first 20 items. When I click on the scrollbar down arrow, the scrollbar moves down a little to occupy the bottom 95% of the scroll area, and the datagrid displays the last 20 items.
It gets weirder. If I move over the items in the grid and scroll down using the mouse wheel, then the items scroll correctly and I can view the whole list, although the scrollbar remains the same size.
And then, if I close the popup and reopen it, the scrollbar now appears with the correct height and it works correctly.
Finally, if I just show the control directly on the page, and not in a popup, it works fine.
What's going on here?! Has anyone else run into this problem? Help!
Update: The problem seems to be the way that I'm showing the popup. For various reasons, I had to implement the popup display in a somewhat tricky way, and it's this that's causing the trouble.
I recoded this, removing some crufty stuff, and the problem went away; see my update. This isn't really a solution as such, but I wanted to close out the question for the record.
When you do not explicitly set the width of a ListBox, it will automatically set its width to the width of its widest visible item. This means that as you scroll up and down and the widest visible data item changes, the width of the listbox itself increases and decreases.
So what is the best way to find the width of the widest item in the list, and then set the ListBox width to that? My data template for the ListBox is a StackPanel containing a CheckBox and a TextBlock, so obviously the Textblock width will vary according to the length of the string in it.
There are a couple of suggestions already here on SO, with answers ranging from "take a guess" to "measure the text size" (how do you measure text size in SL without placing it in a UI element?).
Can anyone throw me a few ideas? I am open to iterating all the data template instances if i have to, although a better option may be to find the longest string and calculate from there?
Have not tried this but it can work:
http://thibautvs.com/blog/?p=1775
"key point is to put the ListBox in a grid column having an “auto” size mode"
ListBox uses VirtualizingStackPanel as default ItemsPanel. Because VirtualizingStackPanel creates UI elements only for visible items you might see the behavoir you describe. To mitigate this behaviour you could try to set VirtualizingStackPanel.IsVirtualizing="False" or change ItemsPanel to StackPanel.
Messing around with this has shown me that it isn't possible without going to the extent of extending/overrideing the ListBox - setting the IsVirtualizing property of the VirtualizingStackPanel had no effect.
The solution that i had to go with was to programmatically choose a good width.
I need to set up a windows form DataGridView, programmatically bound to a list, such that only 6 rows are visible to the user (i.e. the grid's height is only 6 cells) and a scroll bar appears when there are more than 6 elements in the bound list. All the rows need to be of the same height. Is there a configuration of properties that does this or do I have to manually set the height of the DataGridView so that only 6 rows would be visible?
Set the size of the control such that at most 6 rows are visible, and set the Scrollbars property so that the vertical scrollbar appears as needed (to Vertical, or Both if you need a horizontal scrollbar as well).
If I understand your question correctly, you're wanting to use paging on the datagridview. If this is correct try this and this. It's a bit convoluted though.