Populate Combobox during invoke command?

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
Locked
User avatar
agenosko
Posts: 19
Joined: Fri Apr 25, 2014 2:30 am

Populate Combobox during invoke command?

Post by agenosko »

Hi Experts,

I've a question regarding Combobox and invoke-command.
Is it possible to populate the Combobox during invoke-command?
My wish is to get already some items inside the Box during invoke-command.
Issue is, that I've to connect to a database which is in another network, so I've to take a "Jumphost".
So, first I've to connect to the Jumpserver, then I can make the Database request.
But right now all the data of the Database populate the Combobox at the end of the invoke-command.
Right now it looks like this:

Code: Select all

$jumphost_request = invoke-command -computername $jumpserver -credential $cred_jumphost -Scriptblock {
		
.....
.....
....
New-Object -TypeName PSObject -Property @{
			'productNames_users' = $productNames_users
			'productNames_LC'    = $productNames_LC
			'productNames'	     = $productNames
			'columnnames'	     = $columnnames
			'ausgabe_TT'		 = $ausgabe_TT
			'columheader_name'   = $columheader_name
			'user_selected'	     = $user_selected
			'productNames3'	     = $productNames3
}
		ForEach ($item in $jumphost_request)
	{
		$productNames_users = $item.productNames_users
		$productNames_LC = $item.productNames_LC
		$productNames = $item.productNames
		$productNames3 = $item.productNames3
		$columnnames = $item.columnnames
		$ausgabe_TT = $item.ausgabe_TT
		$columheader_name = $item.columheader_name
		$user_selected = $item.user_selected
	}

$combobox_Tabellenname_DB_TT.Items.AddRange($productNames)
....



But this way has a lot of disadvantages. It would be much better, that some data are already inside the Combobox before the Request really ends.

Thanks for any idea.

jvierra
Posts: 14553
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Populate Combobox during invoke command?

Post by jvierra »

There is not enough information to answer your question. I cannot see why ou have to use a "jump" server. Most databases allow direct queries.

There are many ways to dynamically fil a ComboBox. Unfortunately any time an event is blocked waiting for external response the GUI will be unusable. Only one event can run at a time.

One way to load a control and keep the form alive is to use a JobTracker.

User avatar
agenosko
Posts: 19
Joined: Fri Apr 25, 2014 2:30 am

Re: Populate Combobox during invoke command?

Post by agenosko »

Thanks @jvierra

Unfortunately the Database isn't directly reachable. Different Networks, Firewalls etc. So only the "Jumpserver" has connection.
Nevertheless your idea regarding JobTracker is an idea.

jvierra
Posts: 14553
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Populate Combobox during invoke command?

Post by jvierra »

You are also loading the ComboBox only after the results are returned and you are returning all objects after conversion. Just return the rows as they are available and add them to the ComboBox a few at a time.

Code: Select all

$sb = {
#		
#.....
#Query that returns rows Uing datareader
#....
    while($reqader.Read()){
        $reader.GetValues()
    }
}
invoke-command -computername $jumpserver -credential $cred_jumphost -Scriptblock $sb |
    ForEach-Object{
        $combobox_Tabellenname_DB_TT.Dataource.Rows.Add($_) 
    }

Locked