Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

powershell to dynamically populate dropdown list with selection in list box

I have a powershell form where I am displaying a list box in the GUI


$objListBox0 = New-Object System.Windows.Forms.ListBox
$objListBox0.Location = New-Object System.Drawing.Size(20,42)
$objListBox0.Size = New-Object System.Drawing.Size(260,20)
$objListBox0.Height = 80

[void] $objListBox0.Items.Add("SERVER01")
[void] $objListBox0.Items.Add("SERVER02")
[void] $objListBox0.Items.Add("SERVER03")
[void] $objListBox0.Items.Add("SERVER04")
    $objForm.Controls.Add($objListBox0)


and then I am using a text box to enter database name.

But instead of text box I'd like to create a dropdown box in which there is a list of databases.

The list should be created based on the selection of servername in the list box.

I'd like to run a database query on the selected MSSQL database SERVER to retrieve the database names:


SET NOCOUNT ON;
SELECT name FROM sys.databases where database_id > '4';

This may be executed as a sqlcmd -S SERVER01 listdbs.sql which can populate the dropbox.

If this is possible, Please let me know how to achieve this.

Thank You!
ASKER CERTIFIED SOLUTION
Avatar of OriNetworks
OriNetworks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DevSupport
DevSupport

ASKER

Thanks I will create a Gigs project later