Elegant Way For This UI to Work? - c#

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.

Related

Winforms, can I use a text box here instead of a combobox? (dropdown list with over 15k options)

For the last few weeks I've been building a product demo for work which includes a winform to enter new customer enquiry information. One of the form elements is a text box which, for the sake of ease, I haven't imposed any validation on so far. However, I now need to make it so that the user can only enter a valid location from an sql database table (containing around 15k streets).
I'm still quite new to C# programming. My first thought was that I should change my text box to a combobox but I seem to remember that when you click on a combobox all the options in the list appear before you've typed anything. Since our computers are slow and there's so many options, I don't really want to flood the screen so I was wondering if there was a way I could continue using my text box and onkeypress (probably the tab key) a dialogue pops up with all the closest matches from the list, prompting the user to select a valid option?
If not, is there a way to stop my combobox from showing the option list until prompted?
I would not think a combobox is not well suited for that many items.
The way I have approach this is to use a separate list view to show matches. You could probably put matches in a drop-down style borderless window, but I find that more complex and may be difficult to make the interaction work well.
I would just have the streets in a separate list view control and apply a filter to that.
Make sure the view is resizable, I find it very frustrating when working with old window controls where the list is tiny due to it being written for 640x480 screens, and does not allow resizeing.
Keep performance in mind, when searching with each key-press you might want to fetch all records and do the search in memory rather than making a sql query for each key.

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 performance issue with Numeric up down and list box

In my Win forms app, i have a Numeric up down and a list box.
when i increase/change value in numeric up down, that many rows are added in list box.
for ex. when i have value '1' in my numeric up down and i change the value to a larger number say '300', it adds 300 lines in the list box but it takes hell lot of time to do it.
is there any way by which i can reduce this time.
any help would be appreciated. thanks.
You can try creating the necessary data (or controls) that will be added first, and maybe do it in a Parallel.ForEach and afterwards add all of them.
Otherwise, only something like data virtualization available in WPF would be of help but i don't know if that exists in WinForms.
Try adding them "on demand". Add only the necessary few that are visible plus a few more and when the use scrolls down, add some more and so on.

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

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.

C# Textbox AutoComplete: Limit to ~50 suggestions

I'm working in C# with a textbox that acts as input for a database (Access SQL) record lookup by id number. I want to be able to use AutoComplete on the text box but with some limitations.
The big issue is that the number of ids in the system is on the order of thousands so instead of filling the AutoComplete box once with all of them, I need to monitor what is in the textbox and only show the autocomplete suggestions when there are ~50 or fewer choices.
Currently, I am doing this query on each KeyDown: SELECT count(*) FROM Table WHERE id LIKE 'textbox.text%'
When the count is less than 50 I fill the autocomplete with the results from a SELECT id version of the above statement. This has led me to several problems, most seem to be C# quirks I don't understand.
1) When I clear or add to the AutoCompleteCustomSet within a single KeyDown event, the actual key pressed does not get added to the string (i.e. normal text box input behavior does not occur).
2) I tried separating the AutoCompleteCustomeSet update to a different event (KeyPress or KeyUp) but this either resulted in a crash, or the autocomplete display would only show briefly before being hidden.
I feel like this problem must be common and I am just going about it the wrong way. Can anyone offer some advice? Thanks!
EDIT: this is Windows Forms
EDIT2: A top 50 select doesn't fix the problem that as the user types (and potentially backspaces and re-types) the top 50 will change.
Did you try the TextChanged event instead ?
I would expect that event to be fired AFTER the textbox has been updated, thus avoiding the quirks you mention.
Can't you just SELECT TOP 50 FROM Table WHERE ...?
Would just limiting your suggestions to 50 work for you?
When your selecting your suggestions you can use a query like this:
SELECT TOP 50 * FROM YourTable WHERE.....
The reason you get crash may be that you get a race condition when replacing the autocomplete source, which is used by a background thread to compute candidates while you are typing (or you put null instead of String.Empty in the candidate list)
Before Windows Vista, the Autocomplete object match candidates with prefix only, so don't populate candidate strings not beginning with the typed string.
Use IAutoCompleteDropDown::ResetEnumerator to reset the candidate list.

Categories

Resources