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.
This topic is 4 years and 1 month 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
agenosko
Posts: 19
Last visit: Fri Jan 26, 2024 11:28 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Fri Jan 26, 2024 11:28 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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($_) 
    }
This topic is 4 years and 1 month 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