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.ListB ox
$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("SE RVER01")
[void] $objListBox0.Items.Add("SE RVER02")
[void] $objListBox0.Items.Add("SE RVER03")
[void] $objListBox0.Items.Add("SE RVER04")
$objForm.Controls.Add($obj ListBox0)
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!
$objListBox0 = New-Object System.Windows.Forms.ListB
$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("SE
[void] $objListBox0.Items.Add("SE
[void] $objListBox0.Items.Add("SE
[void] $objListBox0.Items.Add("SE
$objForm.Controls.Add($obj
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER