Multiselect WPF Listbox Make multiple selections with one click

I have a list of multi-images with binding to binding to binding to datatable. When I select listboxitem, I want some other list items in the same list to be selected automatically. I want several items to be selected with one click. How can i do this? I cannot do this in the SelectionChanged event, because it fires the same event again and completely destroys my logic.

Please, help. Any help would be greatly appreciated.

UPDATE:

My list is already bound to a datatable that has an IsSelected column. I use the value of this column in the style installer to make the listboxitem selected. Suppose I have 10 rows in a datatable. Now, if the user selects the second listboxitem, I can get that isequited from the corresponding row in the database as 1.

But how can I select other items at the same time? I think, as Kent said, I would rather use the property for binding. But how can I use a property to bind a list to data?

+4
source share
5 answers

Bind IsSelected to a property in your data class. When the property is changed, follow the logic to update the IsSelected property in other data objects:

 <ListBox> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="IsSelected" Value="{Binding IsSelected}"/> </Style> </ListBox.ItemContainerStyle> </ListBox> 

Then in your data class you can have something like this:

 public bool IsSelected { get { return _isSelected; } set { if (_isSelected != value) { _isSelected = value; OnPropertyChanged("IsSelected"); UpdateOtherItems(); } } } 

Or you could force the data item to raise the IsSelectedChanged event and have its own class to control the selection dependencies.

+8
source

Has the “SelectedItem” property with the installer logic for this property that handles the selection of your other “similar” elements?

Perhaps, as I would say, it is difficult to say with more detailed information.

0
source

I am working on a similar one.

I have separate combined fields that I load using the Selected Value property from the database, and now I'm working on multi-byte list boxes for which I have a list of selected in the database that I need to bind to the selected list for my list.

I see no way to do this without a loop.

I see the read / write properties of the list to get or set the Items, SelectedItem / Index / Value properties or read-only properties for Items or SelectedItems.

0
source

This may be a hoax, but when you add elements to the SelectionChanged event, you tried to set IsEnabled to false, when you selected several elements and then returned it to the true afterword, I think it is supposed to keep the event controls from firing?

0
source

I created a MultiSelectCollectionView that you might find useful here:

http://grokys.blogspot.com/2010/07/mvvm-and-multiple-selection-part-iii.html

0
source

All Articles