I want a box that shows 5 items (of the 20 that are available). The other fifteen are scroll-able to.
When I click on one of the items, it acts like a combo box in that it is the one selected/highlighted.
Is there a control for doing this already?
I have tried using the combobox and setting the height on it, but the height is still only one row high.
ComboBox cboResults;
cboResults = new ComboBox();
cboResults.Height = 500;
cboResults.DropDownStyle = ComboBoxStyle.DropDownList;
cboResults.IntegralHeight = true;
frmLookup.Controls.Add(cboResults);
Am I using the wrong control?
Try to use ListBox, setting a default height you can achieve the scrollable behaviour you want.
A ComboBox is a combination of an editable field with a list. The list either drops down or is shown and scrollable. For this set the DropDownStyle=Simple!
However a simple ListBox is probably more suitable, unless you do want to allow the user to enter data.
Of, if you want to display more complex data, maybe with columns a ListView is best; I found I promote most ListBoxes sooner or later to ListViews..
Related
I'm maintaining a C# application written with windows forms. I now need to have a list view where every item has a few custom controls.
Every item need to have title and a combobox. The problem is that the data for the custom boxes will be different. So for example Item 1 could have a ComboBox where you can pick 1-3. Item 2 would have a combo box where you can pick 1-2.
So in the property column I need a string, and in the value column a combobox, with different data sets for different items (or at least for different kinds of items)
I've been on this problem for a while, and I don't really know where to go from here.
Why don't you use a Property Grid control? It is composed by two columns, the left one being a fixed text for the key/title and the right one is dynamic, in the sense you can have comboboxes, textboxes, color selection controls, etc. for the value the user can input/select.
I want to use a Combobox, with DropDownStyle=Simple, which changes the list of items when typing some content in the box.
The loading of the items is OK, and I can see them in debugging mode on the Items property, but the dropdown is not shown and seems to be empty.
I also tried to force the display of the dropdown putting
MyComboBox.DroppedDown = True;
Any clue on this behavior?
According to MSDN:
ComboBoxStyle.Simple is the style that
Specifies that the list is always visible and that the text portion is
editable. This means that the user can enter a new value and is not
limited to selecting an existing value in the list.
So if the list is always visible then where is it. It is not visible because of the Size that is set by default. Change the height like so:
MyComboBox.Size = new System.Drawing.Size(256, 150);
The 150 denotes the height in this case. By default the height was something like 21 which was very less. Increase the height to some appropriate figure and the list should be visible.
Also a very important note: Do set the ComboBoxStyle before you set the size. I do not know why but it seems some invalidation or something is amiss here.
So the following would work:
//Will work
MyComboBox.DropDownStyle = ComboBoxStyle.Simple;
MyComboBox.Size = new System.Drawing.Size(256, 150);
but this will not:
//Will not work
MyComboBox.Size = new System.Drawing.Size(256, 150);
MyComboBox.DropDownStyle = ComboBoxStyle.Simple;
The latter might work with some explicit invalidation calls but i did not verify that.
If you want a drop down to open up when the user clicks on the drop down arrow then you would have to use the other combo box styles. In the Simple style the drop down arrow would not appear and the list would always be visible as the MSDN definition suggests.
I would post this as a comment but my reputaion isn't high enough.
How are you populating the ComboBox?
Your problem seems very familiar to:
ComboBox will not update its display list unless you change selections first
I added a listbox control to log entries but I want the entries to have a date in the right side. Apparently, I'm able to only align it one side and not able to have this text on both the side. I was wondering if it is possible. Here's a photoshopped image to describe what I need. The right side date doesn't actually turn up. I added that through photoshop but its exactly what I need.
I would like to suggest you to use ListView instead of Listbox. You can show your list with multiple columns in detail view. You can also align column value, Hide header using HeaderStyle property.
If you don't want to use ListView control and want to use ListBox. then you have three options to do that.
You can draw item using OwnerDraw method.
You can add label to the ListBox. but, it creates lot of problems when you are trying to scroll items.
Set the listbox font Courier New and use String.PadRight or String.PadLeft to place space between two item. But, in this method the item will be return with space. Here you need to process to separate that field.
I am currently working on a project that displays user data in a grid, each user has a total and when clicked expands out to show the sub items that make up that total and they can be expanded again to show even more details.
I currently achieve this by using a DataGridView with its data bound to a DataTable, I hide the sub items for each user in the "RowsAdded" event and then just show/hide them as the main user lines/sub lines are clicked.
The Main problem with this is the scroll bar jumps a lot when data is changed and I require it to only move when the user wants it to.
I also have a requirement that no line must ever be covered and the parent lines should show totals of the values in the child (I can do this part manually the more important part is that its not a grouping like with a outlook style list).
My question is: Is there a better way to have expanding entries in a table format? And if hiding and un-hiding is the only way then any idea how to fix the scrolling problem?
I have tried hiding and showing lines as I have already said and I have also tried hiding and showing another Control (in this case another DataGridView) the problem with this approach is that it covers the other rows as I have yet to find a suable way to pad out a space for the control to be in.
You can use the following code to eliminate the scrolling animation.
dataGridView1.ScrollBars = ScrollBars.None;
// Do your show/hide on your datagridview rows
dataGridView1.ScrollBars = ScrollBars.Both;
In the End there was no satisfactory way to do this with winforms so I was forced to swap to WPF and I had everything running in about 2 hours.
My end solution was to use a DataGrid with rowdetails that contain a DataGrid.
How to disable editing or hide text edit field, when DropDownStyle = Simple for Combo Box control?
MSDN on ComboBox.DropDownStyle:
The DropDownStyle property specifies whether the list is always displayed or whether the list is displayed in a drop-down. The DropDownStyle property also specifies whether the text portion can be edited.
Docs on ComboBoxStyle.Simple:
Specifies that the list is always visible and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list.
So, ComboBoxStyle.Simple suggests that list can be edited by user and it's confusing to disable edit with this DropDownStyle selected. Alternatives:
If you are ok with drop-down list use ComboBoxStyle.DropDownList
If you want to display a non-editable list with a view similar to ComboBoxStyle.Simple consider using ListBox
If you really need to achieve this effect on Combox you can just catch the events like "TextChanged" and then setting it back to "" and asking if (!comboBox1.DropDownStyle == ComboBoxStyle.Simple) before adding items to Items collection. Although it seems there are better ways to achive similar functionality using listbox as suggested before.