Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

C# WPF - How to select Multiple Items programatically in a Databound ListBox...

$
0
0

Using Windows Presentation Foundation for a Dialog.

The underlying code for the ListBox is:

   <ListBox Name="listBox1" Width="300" Height="600" Margin="0,0,5,0" SelectionMode="Multiple" />

My code saves data from this ListBox whether a single or multiple items are selected.

The ListBox has a hidden item which is the Key when the data is stored and the visible data which is shown.

---

The problem is that when attempting to select multiple items that are populated in the Listbox from the Database, I can only select 1 using "listBox1.SelectedIndex = xx;" where xx is the integer offset of the matching item. So this is not the right method to restore the items that were selected previously.

Using "listBox1.SelectedItems.Add(DisplayData);" where "DisplayData" is a string that matches exactly to what is in the ListBox does not select the desired items.

Using "ListBoxItem item = (ListBoxItem)listBox1.Items[xx]; // THIS line exits the subroutine!" which isn't helpful at all.

The IsSelected Property doesn't seem to be exposed so that I can use it to allow multiple ListBox items to be selected.

---

What am I missing?

Surely someone has successfully loaded a Databound ListBox and reselected Multiple Items after the ListBox has been loaded.

BillNew


DirectShow Filter Graph Spy: http://alax.info/blog/777 Extremely helpful for finding deep details for DirectShow Graphs.


Viewing all articles
Browse latest Browse all 18858

Trending Articles