Using Powershell to Databind a Combobox with a Value and some Text

Creating a combobox in Powershell and adding an item to it is a relatively trivial task:

The text of the selected combobox can be obtained like so:

This is a combobox in its most simplistic¬†form. The trouble is, I’m from an ASP.Net background and it’s often handy to bind a value (the hidden reference to the selected item – usually a primary key integer) AND some text (the value that the user sees in the combobox – the ‘friendly’ name). ¬†This requires a bit more leg work to implement and can be done by using a datatable, adding data to the datatable, and binding this datatable to our combobox like so:

1 thought on “Using Powershell to Databind a Combobox with a Value and some Text

  1. If I wanted to select a value other than the first value entered, without rearranging the values, how would I do this?

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.