TonyW TonyW - 4 months ago 12
Vb.net Question

Listbox with Expanders to another listbox

I'm trying to move an item from expander in listbox (keep the item there) and copy it to another listbox.

<ListBox Name="lbAvailableColumns" Grid.Row="1" Grid.Column="0">
<Expander Header="Account" Background="Transparent" BorderBrush="{x:Null}" >
<StackPanel>
<ListBox>
<ListBoxItem Content="Account Is Locked Out"/>
<ListBoxItem Content="Expiration Date"/>
<ListBoxItem Content="Last Lockout Date"/>
<ListBoxItem Content="Must Change Password"/>
<ListBoxItem Content="Password Age(Days)"/>
<ListBoxItem Content="Password Last Changed"/>
<ListBoxItem Content="Password Never Expires"/>
<ListBoxItem Content="Password Not Required"/>
<ListBoxItem Content="Smart Card Required For Logon"/>
<ListBoxItem Content="User Cannot Change Password"/>
<ListBoxItem Content="Username"/>
</ListBox>
</StackPanel>
</Expander>
<Expander Header="Exchange" Background="Transparent" BorderBrush="{x:Null}" />
<Expander Header="General" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Group Membership" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Organization" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Other" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Profile" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="System" Background="Transparent" BorderBrush="{x:Null}"/>
<Expander Header="Telephone" Background="Transparent" BorderBrush="{x:Null}"/>
</ListBox>


I'm trying to do the following, and am having a bit of trouble.

enter image description here

Trying to copy item from the expander listbox, to the visible columns listbox. Any ideas?

Answer

I've written one of those things, but without the grouping into expanders. The grouping is a side issue if you do it right.

What you want to do is give your viewmodel two ObservableCollections of some data item class, say FromItems and ToItems. Bind those two collections in XAML to the ItemsSource properties of the two ListBoxes.

The data item class could be a very simple quickie class with two properties (not fields): Say, Name and GroupName, both strings. Group by GroupName. Here's a group template expander answer, here's how to do the actual grouping and set DisplayMemberPath="Name" on each ListBox.

The > button removes the left listbox's SelectedItem from FromItems, and adds it to ToItems. The < button does the reverse. You may not want to remove from FromItems, but then you'll have to be careful not to add them to ToItems twice.

Comments