Page 1 of 1

Reusing groups of controls

Posted: Wed May 12, 2021 10:14 am
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.

Re: Reusing groups of controls

Posted: Wed May 12, 2021 10:27 am
by jvierra
Use a dataGridVi3ew with ComboBoxes for the variable selections in each row.

Re: Reusing groups of controls

Posted: Wed May 12, 2021 12:56 pm
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/

Re: Reusing groups of controls

Posted: Wed May 12, 2021 1:48 pm
by jvierra
Simple example:
Screenshot 2021-05-12 164600.png
Screenshot 2021-05-12 164600.png (9 KiB) Viewed 3121 times

Re: Reusing groups of controls

Posted: Wed May 12, 2021 3:39 pm
by jvierra
Here is more exact example.
Screenshot 2021-05-12 183652.png
Screenshot 2021-05-12 183652.png (9.62 KiB) Viewed 3101 times

Re: Reusing groups of controls

Posted: Thu May 13, 2021 6:28 am
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.

Re: Reusing groups of controls

Posted: Thu May 13, 2021 6:38 am
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.

Re: Reusing groups of controls

Posted: Thu May 13, 2021 8:25 am
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.

Re: Reusing groups of controls

Posted: Thu May 13, 2021 10:56 am
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.