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.
This topic is 2 years and 10 months 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
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

Reusing groups of controls

Post by b_warren »

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 3133 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Reusing groups of controls

Post by jvierra »

Use a dataGridVi3ew with ComboBoxes for the variable selections in each row.
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

Re: Reusing groups of controls

Post by b_warren »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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 3117 times
Attachments
Demo-DGVComboBox3.psf
(18.11 KiB) Downloaded 95 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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 3097 times
Attachments
Demo-DGVComboBox3.psf
(15.67 KiB) Downloaded 76 times
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

Re: Reusing groups of controls

Post by b_warren »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
b_warren
Posts: 11
Last visit: Tue Jan 09, 2024 9:48 am

Re: Reusing groups of controls

Post by b_warren »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 2 years and 10 months 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