Hi,
I'm creating a form for the New Standard File command. On this form I'm putting a ListBox where the user can multiselect some options:
<ListBox Grid.Row="18" ItemsSource="{Binding Prop[WandType].ListValues}" Name="WandType" Grid.Column="1" MinHeight="50" MaxHeight="50" SelectionMode="Multiple"/>
Within the default.PS1 I'm joining the selected values to a string and sync this with the property:
function WandList_OnSelectionChanged { $WandList = New-Object System.Windows.Forms.ListBox $WandList = $dsWindow.FindName("WandType") $SelectedTypes = $WandList.SelectedItems $ofs = ';' $Prop["WandType"].Value = [String]$SelectedTypes }
So far, everything is working fine.
When the Edit File Datasheet Dialog is initialized, I'm wanting to preselect the values of the property. Is this possible with a listbox? How can I preselect multiple items in the listbox. I've managed to do it for one item, but not for multiple items:
$WandList = New-Object System.Windows.Forms.ListBox $WandList = $dsWindow.FindName("WandType") $WandTypesList = $Prop["WandType"].Value $WandTypesList.Split(";") | ForEach {$WandList.SelectedValue = $_}
Regards,
Peter
Solved! Go to Solution.
Solved by marco.mirandola. Go to Solution.
Hi Peter, the ListBox provides the property SelectedItems, which has an Add function. So, in order to set the selected items in your ListBox, you would do something linke this:
$dsWindow.FindName("WandType").SelectedItems.Add("Item1") $dsWindow.FindName("WandType").SelectedItems.Add("Item2") $dsWindow.FindName("WandType").SelectedItems.Add("Item3")
now, taking your code it would be something linke this:
$WandTypesList.Split(";") | ForEach {$WandList.SelectedItems.Add($_) }
looking to your code, i see that you set the $WandList variable with New-Object .... Why is that? The beauty of PowerShell is that you don't have to define variables, and the variables changes their type as needed. So, in your case, you can simply do
$WandList = $dsWindow.FindName("WandType")
ciao
marco
Hi Marco,
This did the trick! Thanks a lot. (I was really close).
I declared the variable to be able to use the intellisense in PowerGui.
Peter
glad i could help. As a tip, you may place a # infront of you declaration line, so that it does not get executed. However, you can select the line w/o the # and execute the selection. This way, the variable is set in PowerGUI and you benefit from the Intellisense, but the line is still commentet. Or of course you could set the variable in the command line underneath.
just a hint
ciao
marco