How to create a custom selectionmode in winforms listbox - c#

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.

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.

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)

Adding Multi-Select Functionality (Java Developer Learning C#)

I'm working on a piece of code that I inherited and am trying to expand it from only being able to select one row to being able to select multiple rows.
Essentially, the item I'm working with displays like a data table. It contains methods for "OnSelectItem" and "OnMouseDown", with "OnMouseDown" checking to see if the click is right mouse button click or a left mouse button click.
Generally, how is functionality to support the ability to support Multi Select implemented? Is it handled through recognization of the mouse clicks in addition to holding down particular keys or is there a different way to implement this type of functionality?
Your comments indicate that you're working with a custom control. So, answers that apply to general Microsoft-supplied controls may not work at all.
You should be able to use the events you've listed already to handle multi-select features in this custom control.
As an example, you could look at the CheckedListBox control. It has a checkbox in front of every row. If the box is checked, that row is "selected". If that's not the type of selection you're looking for, then you can look at the ListView control in Detail mode. It allows you to set options that let the user highlight multiple rows, using CTRL and/or SHIFT to modify the way the mouse-click affects selection.
As far as multi select is concerned from my point of view it also requires key board support in addition to mouse click
1) In Controls if we press shift key and then press up or down arrow key then also row get selected
2) We can also implement multi select functionality by checkbox column, i am not sure this is possible or not in your case
3) There is also fundamental of Fixed Column, on mouse click of that column entire row is getting selectd

C# dropdownmenuitem clicked and listview editing

I have 2 questions concerning C#.
1) I have a dropdown menu with several items in them. They are clickable, but when I click one, the older clicked one stays selected. Click another and the 2 original ones stay selected, and so on. I don't want this. What I want is that when I click one of the dropdownitems, that one is that selected one and the others are not.
2) I have a listview items on a winform. I loaded some string elements into it from a file. Now what I want to do is to be able to edit those strings and even add strings, just by clicking on the rows in which the data goes.
I've checked google and MSDN for these problems, but nothing helps, so I turn here.
2) The ListView does not support that type of action. You can roll your own (pain in the #$$), or perhaps a DataGrid would be better suited to your purpose.
EDIT:
This link may help
This one too
For #1 I'm a little confused. If the DropDownStyle isn't set to simple something strange is occuring. It's not much but maybe you could try recreating the control.
For #2 the easiest solution I can think of is to set a TextBox to be equal to the selected text value from your listview. After that write a little function to update the selected index of the listview with the edited text from the listview.
Please comment if you have any more information about #1.

C# Day from Week picker component

This question is for C# 2.0 Winform.
For the moment I use checkboxes to select like this : Monday[x], Thuesday[x]ΒΈ... etc.
It works fine but is it a better way to get the day of the week? (Can have more than one day picked)
Checkboxes are the standard UI component to use when selection of multiple items is allowed. From UI usability guru Jakob Nielsen's article on
Checkboxes vs. Radio Buttons:
"Checkboxes are used when there are lists of options and the user may select any number of choices, including zero, one, or several. In other words, each checkbox is independent of all other checkboxes in the list, so checking one box doesn't uncheck the others."
When designing a UI, it is important to use standard or conventional components for a given task. Using non-standard components generally causes confusion. For example, it would be possible to use a combo box which would allow multiple items to be selected. However, this would require the user to use Ctrl + click on the desired items, an action which is not terribly intuitive for most people.
checkbox seems appropriate.
You can also use a ListView with CheckBoxes on...
for a little less hard coding.
Checkboxes would work fine, and there is a preexisting paradigm of that usage in Windows Scheduled Tasks. To see that example, create a scheduled task and select Weekly for the frequency.

Categories

Resources