Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data Standard: Listbox SelectedItems Binding

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
515 Views, 3 Replies

Data Standard: Listbox SelectedItems Binding

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

3 REPLIES 3
Message 2 of 4
marco.mirandola
in reply to: Anonymous

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

 

coolOrange
www.coolorange.com
Message 3 of 4
Anonymous
in reply to: marco.mirandola

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

Message 4 of 4
marco.mirandola
in reply to: Anonymous

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

 

coolOrange
www.coolorange.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report