Multi combobox update

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 7 years and 5 days 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
christouffe
Posts: 27
Last visit: Thu Mar 23, 2017 8:29 am

Multi combobox update

Post by christouffe »

Hi guys,

I have a question :

I make a gui with 4 combobox and I would like to put in these 4 combobox 4 values of a CSV file.
For example in my csv :

Name;Lastname;age;Country
John;doe;23;USA

I would like to put :

John in combobox1
doe in combobox2
23 in combobox3
USA in combobox4

when I select John in the first combobox manually.

How can i do this plz?

Thanks :D

Chris
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi combobox update

Post by jvierra »

What you are asking is too vague. You need to describe this better.

If you are looing for how synchronize controls then please tell us what your source is.

Why would you use ComboBoxes to display rows in a CSV, Use a DataGridView.

To sync other controls with a ComboBox use a DataTable. You can load a SCV into a DataTable using "ConvertTo-DataTable".
User avatar
christouffe
Posts: 27
Last visit: Thu Mar 23, 2017 8:29 am

Re: Multi combobox update

Post by christouffe »

I have a powershell form for my computer inventory

Image

When i select a client "LM72,NATINOV,etc..." in the first combobox, I would like the other combobox (Nom machine,Num MTC,etc..) to automatically retrieve information according to the selected client in my csv file.

Is it better decription? :D

Chris
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi combobox update

Post by jvierra »

What does your CSV file look like?

We wouldn't use ComboBoxes for this. Use textboxes to display associated fields. Bind to a DataTable and you will not need to write any code.
User avatar
christouffe
Posts: 27
Last visit: Thu Mar 23, 2017 8:29 am

Re: Multi combobox update

Post by christouffe »

My csv look like this for each client:

client;Nom machine;num MTC;RAM;DD;Ecran;Taille Ecran
LM72;D-1014253;1014253;2Go:500Go;Samsung;24"
LM72;D-1014254;1014254;8Go:250Go;LG;23"
LM72;D-1014255;1014255;4Go:300Go;HP;22"
LM72;D-1014256;1014256;6Go:800Go;Samsgun;24"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi combobox update

Post by jvierra »

Why are you using all ComboBoxes? You can only look at one row at a time. It makes no technical sense is not really possible to do. You also have all duplicate rows. At a minimum you should have one ComboBox and the rest would be textboxes. Load a DataTable and ad it would display one row per client chosen.
User avatar
christouffe
Posts: 27
Last visit: Thu Mar 23, 2017 8:29 am

Re: Multi combobox update

Post by christouffe »

It is a powershell interface for my on-site technicians that they will use on tablet. I already have a list of hardware on site, they simply need to update this list with this powershell Gui on their tablet
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi combobox update

Post by jvierra »

Use a DataGridView.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Multi combobox update

Post by DevinL »

I've attached a rough sample that should achieve what you want.

Provide the path to your CSV for each customer in your ComboBox, then load the data into the DataGridView using the same process as I do on lines 20 - 22:
  1. $PrimalabFile = "D:\Temp\TempData.csv"
  2. $FileData = Import-Csv -Path $PrimalabFile -Delimiter ';'
  3. $DataTable = ConvertTo-DataTable -InputObject $FileData
  4. Update-DataGridView -DataGridView $datagridview1 -Item $DataTable
NOTE: The Update-DataGridView cmdlet is added to the psf file when you add the DataGridView object.

EDIT: The TempData.csv contains what OP said was in their client file:
client;Nom machine;num MTC;RAM;DD;Ecran;Taille Ecran
LM72;D-1014253;1014253;2Go:500Go;Samsung;24"
LM72;D-1014254;1014254;8Go:250Go;LG;23"
LM72;D-1014255;1014255;4Go:300Go;HP;22"
LM72;D-1014256;1014256;6Go:800Go;Samsgun;24"
Attachments
DataGridView_Sample.psf
(35.17 KiB) Downloaded 140 times
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi combobox update

Post by jvierra »

For textboxes use the SelectedIndexChanged event to set the other controls. You could also just bind the same table to all ComboBoxes.

Using a grid can only be well synced with a binding adapter.
  1. $cbCustomer_SelectedIndexChanged={
  2.     $txtName.Text = $cbCustomer.SelectedItem.Name
  3. }
This topic is 7 years and 5 days 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