Reusing groups of controls

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.
Locked
salient
Posts: 11
Last visit: Wed May 19, 2021 8:21 am

Reusing groups of controls

Post by salient »

Hello,

I want to set values for a group of objects and then reuse those same controls for other groups.
I am not sure what is the right way to approach this or if it is even possible.
I attached an example of what I am envisioning.
Is this on the right track or should it be done a different way?

Thank you.
Attachments
reusing control groups.png
reusing control groups.png (12.84 KiB) Viewed 2183 times

jvierra
Posts: 14872
Last visit: Tue Jul 27, 2021 9:44 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Reusing groups of controls

Post by jvierra »

Use a dataGridVi3ew with ComboBoxes for the variable selections in each row.

salient
Posts: 11
Last visit: Wed May 19, 2021 8:21 am

Re: Reusing groups of controls

Post by salient »

Thank you for the suggestion.
I am looking into that based on these two articles:
https://www.sapien.com/blog/2020/09/08/ ... w-control/
https://www.sapien.com/blog/2015/01/19/ ... -csv-data/

jvierra
Posts: 14872
Last visit: Tue Jul 27, 2021 9:44 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Reusing groups of controls

Post by jvierra »

Simple example:
Screenshot 2021-05-12 164600.png
Screenshot 2021-05-12 164600.png (9 KiB) Viewed 2167 times
Attachments
Demo-DGVComboBox3.psf
(18.11 KiB) Downloaded 50 times

jvierra
Posts: 14872
Last visit: Tue Jul 27, 2021 9:44 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Reusing groups of controls

Post by jvierra »

Here is more exact example.
Screenshot 2021-05-12 183652.png
Screenshot 2021-05-12 183652.png (9.62 KiB) Viewed 2147 times
Attachments
Demo-DGVComboBox3.psf
(15.67 KiB) Downloaded 35 times

salient
Posts: 11
Last visit: Wed May 19, 2021 8:21 am

Re: Reusing groups of controls

Post by salient »

Thank you for the demo. I see how you can set the column type in the Properties window. Do you know how to do this in code?

Another thing I still don't understand is how to populate the rows with data for each column and preserve the column type.

If I use the Update-DataGridView function it appends new columns instead of reusing them by name.

Thank you.

jvierra
Posts: 14872
Last visit: Tue Jul 27, 2021 9:44 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Reusing groups of controls

Post by jvierra »

The code shows how to create that empty rows based on the VMs you are trying to configure. It can also be done from a CSV or any other object collection. You can enumerate any collection and create one row per entry in the collection.

Before trying to work with forms, which is an advanced subsystem of Windows and of the Net Framework you will have to learn PowerShell.

salient
Posts: 11
Last visit: Wed May 19, 2021 8:21 am

Re: Reusing groups of controls

Post by salient »

Thank you. I am pretty proficient with PowerShell just not Forms which is where I am trying to learn.

I am working on another demo project and have iteration working for creating the columns and rows as well as assigning $null to the DataSource when changing value groups.

The only part I dont see is how to specify the column type in code. It appears to be using a DataGridViewComboBoxColumn.

jvierra
Posts: 14872
Last visit: Tue Jul 27, 2021 9:44 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Reusing groups of controls

Post by jvierra »

You are only working with strings so no column type is needed. The default column in the DGV is a textbox and a string for the ComboBox. No need to change that, just follow my template.

No need to assign $null as reassigning the table will clear the column data when assigning.

You assign the type in the column properties in the column editor of the DGV. Carefully review the columns as I configured them in teh column property editor.

Locked