How can I have a ComboBox retain the recently entered values? - c#

I have a WinForms program in c# that features a text field that I would like to replace with an editable ComboBox.
The effect I would like to achieve is similar to the OpenFileDialog, or to some extent the Address bar in Windows Explorer. That is, when you enter in a valid item, that item is added to the list of possible values that the dropdown displays. I would also like this to persist on subsequent runs of the program.
So, basically
Program runs for the first time, ComboBox is blank and has nothing in the list
User enters a value into ComboBox and hits enter (or a button), value is used and then added to the ComboBox's list
User exits program
User re-enters program, ComboBox is blank but the value used in the previous session is in the list.
I can imagine several ways to implement this, but it just seems like something for which there might be an easy way to accomplish that I don't know about. Like how someone would implement autocomplete only to discover that the control supported it already.
If not then I can just go ahead with some other way of adding and persisting the information, I was just curious if there was something readymade already.

From the properties list of the comboBox you can choose the DropDownStyle as DropDown and from the Misc choose the autocompletemode to (suggest) or (appened).
when user enter something, it will be saved, and when he runs the app in the next time, you should fill the comboBox with the options or give a custom source from the misc too.

Related

How to create a custom selectionmode in winforms listbox

I have a listbox in a winforms application that I would like to give a selection behavior that is different than the built in options for the control.If I choose multi-extended, I get what we are accustomed to - ability to use shift or control to select multiple items in the list. The multi-simple option lets you select individually and leave the item selected until you delect it. I'm trying to deal with a slightly different problem that could be solved by a combination of the two options. My users want to be able to use the shift key to highligh a long list and they don't want to accidentally lose their selection if they mistakenly click on one other item in the list. My thought was to keep everything hightlighted until they click a clear button. I kind of think they are asking for something that is not what Windows is meant to do and should not be allowed to do but I thought would post the question so see if anyone has done this before.

Winforms UI Dynamically Displaying Parts

I came across a tutorial and some example code for an audio converter. You select the format you want to convert to from a drop down, and when you do all sorts of options appear in a previously blank area, different options based on the format you choose. It's called Audio Converter .NET and is from same author as Audio CD Ripper .NET. I can't find the tutorial, but here is a screenshot.
See how on the right there is extra controls that are not on the left. I was experimenting trying to add another category. I added it to the dropdown, but am unsure how to make it so certain fields come up when it is selected.
I understand that they create those controls for those items, but I don't see how they call the correct one when the combo box selects something. I see controls are created, but if I try to duplicate the controls into another entry in the combo box they don't show up for either the new or old one I was duplicating from.
What's the best way to go about achieving something like this?
Thanks
The easiest way is to create the controls needed for every option in the dropdown inside a panel, and simply turn it's visibility property from false to true whenever it's corresponding option is selected using the combobox's SelectedIndexChanged event handler. (And don't forget to turn the current visible panel's visibility to false)

WinRT XAML ComboBox opens in middle of list

So one particular behavior of the XAML combobox in WinRT is causing me a huge headache, because my client sees it as a defect, and doesn't care if it's the behavior of the control, he wants it changed. However, I cannot find anything that tells how to change it. The behavior I'm speaking of is that when nothing is selected the ComboBox popup opens displaying the ItemsSource in the middle of the list. I have a sorted list of countries, with the exception of US, UK, CAN being at the top. These 3 items are the most often selected items and the client wants them on top rather than having to scroll through the list to find them. That's easy enough, but because the list opens in the middle, you still have to scroll quite a bit to get to them. Is there some property I'm missing that turns this behavior off? I was able to finally convince them that the CarouselPanel wasn't a defect, but this one isn't going to fly.
Thanks in advance!
UPDATE:
So this combobox is databound through a ViewModel. in this instance, the ViewModel has no value (it is an empty string) for that particular property and so the Combobox shows empty, which is fine and desirable. When you click on the Combobox to select a value, it displays the list in the middle of the available values. this is the behavior that is undesirable. it should be showing the 1st value in the list at the top!
Well, one would think that the out of the box Combobox (there is no other built in dropdown control) would be able to work like any other combobox control in any other MS technology to date, but of course this is MS, so why should things be consistent. At any rate, I ended up having to create a "blank" entry and pre-select that item if the value in the VM is empty, and then write code in the setter of that property to ignore if "blank" item if it is selected. It's kludgy and wreaks of code smell, but it works
When you set the SelectedItem property to an object, the ComboBox attempts to make that object the currently selected one in the list. If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index. If the object does not exist in the list, the SelectedIndex property is left at its current value.

Elegant Way For This UI to Work?

in VS .NET 4.0 :
So I have some ComboBoxes that query a server for data that match the text in the ComboBox, when the ComBobox text is changed(event).
I want the ComboBox to drop down when the query is done so that the user can see the results and perhaps use them.
The problems :
Rapid-fire queries => Rapid-fire dropdown menu (not very helpful)
Changing the contents of the dropdown causes the text input cursor to reset to the first position in the field. Typing more than 3 characters before the cursor is forced to the first position is very hard. - this is the default behaviour of ComboBox as far as I know
Pressing 'down' to scroll through the list of suggestions causes the very first entry at the top of the dropdown to be put into the text field. Preferably that doesn't happen unless the user hits Return or clicks it.
What I would like :
Overcoming the dropdown-cursor repositioning issue. (this above all)
Scroll list with arrow keys without being forced to select anything.
Limit the rate at which the server is queried.
I have my own solutions in place, but they look terrible at the moment.
I'm handling dropdown and query timings with Timer objects, but my implementation prevents a query from going on while the user is typing, and the dropdown doesn't always occur at the right time if the user types too fast or too slow.
Thank you to those that try to help!
I'm not sure if Iunderstand exactly what you want but personally I'd consider skipping the Combobox and use a ListView instead. Possibly a hidden one that I'd only show at the end of the query and then a Textbox that the user can type in.
Feels like you're trying to use the Combobox for something it's not meant for.

In Winforms, can I configure the combobox to allow values not in the drop down list?

I have a combobox that displays a list of 'active' objects the user can select from. However, if the user goes into some older data screens, the selected values of some of the comboboxes might be old and 'inactive' objects that aren't in the current list.
I want the combobox to just display the old value even though it is not in the list. And I don't want the user to be able to manually edit it either.
Any suggestions?
Thanks!
Isaac
I would assume that it's your code that is removing the objects from the ComboBox in the first place, so you just... don't do that. To disallow typing into the ComboBox set its DropDownStyle property to ComboBoxStyle.DropDownList.

Categories

Resources