What control to use?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

What control to use?

Post by DarkLite1 »

Product, version and build:
32 or 64 bit version of product: 64 bit
Operating system: Win Srv 2012R2
32 or 64 bit OS: 64 bit

We're trying to figure out how we can best have a dropdown list that contains two columns. For example:

-------------------------------
Select citrix farm V
--------------------------------

When clicking on the downwards arrow (V) it should display:

----------------------------------
ServerName1 | XenApp 6
ServerName2 | XenApp 7.15
----------------------------------

After selecting one from the list it should display:
----------------------------------
ServerName1 | XenApp 6
----------------------------------

For now we use a simple ComboBox that contains both values concatenated to one string. Which makes it hard to work with the values selected, as they each represent a property. I looked at a DataGrid, but it doesn't show a drop down box with a small arrow.

Any advice would be helpful. Thank you very much.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: What control to use?

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]

There is not built-in multi-column ComboBox. I'm not clear as to what you are trying to accomplish. Do you want to distinguish the two values more? Or do you want a specific value when selecting an item from combobox? If so, I recommend using objects with properties and then set the ValueMember property of the combobox to the name of the property you wish to use as the value.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: What control to use?

Post by jvierra »

Easiest way is to create a three property object with one to display. Add the objects to the "Items" of the ComboBox and set the "DisplayMember" property you want to display. Items can be retrieved by name:

Object is:
DisplayName, ServerNAme, AppNAme

$ComboBox.Items[1].ServerName

In SelectedIndexChanged:

$combobox.SelectedItem.ServerName
$combobox.SelectedItem.AppName
This topic is 5 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked