ASP:ListBox | Multi Select | Keep selected values when selecting a new one - asp.net

1) Have a listbox with 3 values out of 5 selected
2) When I click to select another value without holding CTRL button, it will unselect over values
How to make it keep other selected values if new value is selected?

This is going to sound like a snide answer, but I don't mean it that way. I just like to look for the simple solutions rather than the complicated onces.
The easiest way to get a control to have the behavior you want is to use a control that has the behavior that you want, rather than modifying the behavior of an existing control.
That said, if you want a list of items where a user can select a bunch of items off the list, and don't want to have to rely on them holding control, you're using the wrong tool for the job.
Use a CheckBoxList instead of a ListBox. If you want it to be scrollable, then set it in a div of a specific height, and set the style of the div to "overflow: scroll".

If you still want to use a ListBox you should use javascript and for each click event fired, you should check if the clicked element is selected/unselected and act accordingly. It's a little bit tricky but at least it is a solution for your problem.

Related

How to figure out the index of a ToggleGroup's selected toggle?

I'm trying to select an item from a list that's sorted the same way as a ToggleGroup I have besides it. However, I found that toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()) always returns -1 (visible in the IndexOutOfBoundsException thrown as I pass it). Is there another way of figuring out the index, or am I at a loss with my approach and need to figure out something completely different?
UPDATE: Apparently, for the first time an item is selected (I have this code attached to changes of selectedToggleProperty()), it works fine (I just get no notice of it because the elements I make visible have no proper layout). However, when an item is selected while another item already is selected, getselectedToggle() becomes null, causing aforementioned behavior.
All of the JavaFX toggle controls have a property called UserData. You should use that to create the links between the toggles and data list. Relying on the index of the toggles in the toggle group is probably a bad idea.

ASP.net: Complex validation of dynamically created DropDownLists

I have a GridView with records of the database.
I create two DropDown lists dynamically for each selected item. That means, if I click select, two DropDown lists appear, the first one defines a start position, the second one a stop position. Both includes numbers (depending on how many items I have selected). If I have selected 5 items, all DropBox controls include the values 1 - 5. Everything is done by code behind.
Now I want to validate that. The stop Control shall be set to a higher one as the start control. Further more, each area that is already used, is not allowed for the next controls. E. g. if I select in the first pair of DropDown lists the area 1-5, I shall not be able to choose 2-6 with the next pair of controls.
How can I do that. I thought about javascript but that could be very tricky because everything is done with code behind. The validation controls are nice, but I don't know how to validate such a complex thing...
Any Ideas?
thank you for your answers!
I dont wont to do a async postback each time, especially because the lists shouldnt be limited during the changes. I solved it in that way:
The user clicks on save, I create a bool array for each dropdown item, then I loop through all dropdownlists in the placeholder. If there is a area from 3 - 5 I set the values with index 3-5 in my bool array to true. If one of these values is already true, there must be a wrong selection in the start/stop positions.
I think, its not a very nice way but works pretty fast and does everything I want. If someone has a better idea, please let me know... ;)
Thanks!
Stefan

How to: Allow for a ListBox to have no selection

I am wanting to allow for a user to deselect all values in a ListBox. Normally, when the user deselects all but one item, that one item cannot be deselected. I want to make it so it can be.
Thanks
Essentially I'm aware of two ways of doing this:
Add an empty item to the list. You can even name this item "None" or something similar. Using a text has the additional advantage that it informs the user.
Use JavaScript to unselect the item that is clicked if it is the last item.
Note, either way, you change the default behavior of the listbox, which is what users are accustomed to. Changing the default behavior is generally not a good idea, which is why I would go for option (1) being the clearest towards your users.

List Component that acts as if control was permanently pressed

I have a list control and i want the user to be able to select many items at a time. Thus I want it to act that if the control key is pressed while he is clicking. Eg if he clicks on a selected row it should become unselected and if he clicks on a unselected row it should become selected.
Do you have any idea how to do this?
Thanks,
Dennis
If you want to follow standard UI Precedent; then set allowMultipleSelection to true and teach your users to use the control and/or shift button to select multiple items.
If you want to select multiple items without having the using press the shift or control button you'll have to extend the List class. I did a sample a while ago using the DataGrid:
http://www.flextras.com/blog/index.cfm/2009/7/23/Flextras-Friday-Lunch--Episode-22--07032009--Auto-Select-DataGrid
http://www.flextras.com/labs/AutoSelectDataGrid/
http://www.flextras.com/labs/AutoSelectDataGrid/srcview/index.html
You can probably use the same technique with a List. But, I don't recommend this approach.

Flex datagrid control with expanding rows

I'm looking for a DataGrid with expandable rows implementation in Flex. I don't want to use Advanced DataGrid control because it's too slow and too complex.
The desired behavior is like this: when you click a row, a panel opens between the rows with some details and the rest of the rows are moved down, and when you click again the panel is closed and the rows are back to normal. If you click the other row, the one that was expanded collapses and the row you clicked is expanded.
You'll probably need to use a custom ItemEditor that responds to clicks and expands itself.
The variableRowHeight property may need to be set to true as well.
The behavior you are describing sounds an awful lot like an Accordion component, though that doesn't quite sound like what you are looking for. Another approach would be to use a List component with a custom itemRenderer that is expanded when in the selected (clicked) state, and collapsed when not selected.
We extended Flex Datagrid component and used custom item renderer for this. We actually expand one cell and resize it to cover all other cells in the same row. While this may be not the easiest solution it works and the Datagrid is very fast.

Resources