Where should be the define of DGV Properties?

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 11 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
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Where should be the define of DGV Properties?

Post by monoeagle »

Hi@All,

the question is a general.

If I create a project in PSS in the mainform.psf the order is as follow:

<MainForm_Load>

<region Control Helper Function>

<other implemented stuff>

Now I added a Datagridview, the columns are defined.
In the MainForm_Load I create a datatable and set the table as source at the DGV.

$datagridviewResults.DataSource = $global:table

If I want to define the Properties I can't do this in the MainForm_Load.

example: $datagridviewResults.Columns[5].Visible = $false;

If I add this there I get an error:
  1. ERROR: The property 'Visible' cannot be found on this object. Verify that the property exists and can be set.
  2. MainForm.psf (40, 2): ERROR: At Line: 40 char: 2
  3. ERROR: +         $datagridviewResults.Columns[5].Visible = $false;
  4. ERROR: +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. ERROR:     + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
  6. ERROR:     + FullyQualifiedErrorId : PropertyNotFound
  7. ERROR:
If I put the property define behind a button it runs. I also didn't found an event where I can put it in.

Any hints?

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

Re: Where should be the define of DGV Properties?

Post by jvierra »

The DGV properties are defined on the property page in the forms designer. Click on the columns editor. The columns can be mapped by name to the table.
In the load event the DGV has not yet been created. It will be created when the load event exits. If you predefine the columns they will be available in the load event.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Where should be the define of DGV Properties?

Post by monoeagle »

yes that's how I normally would do this, but without a datatable until now.

But If I define the datatable and set it as the source of the dgv new columns appears, as I created in the datatable.

How are the steps?

- define the columns in the properties
- set all properties (visibility, width ......)
- create empty datatable
- set datatable as source

If I don't create columns in the datatable, I'll get an error if I try to add a row in the datatable:
  1. ERROR: Exception calling "Add" with "1" argument(s): "Input array is longer than the number of columns in this table."
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Where should be the define of DGV Properties?

Post by jvierra »

The table column names much match the column "DataPropertyName" or the columns will just be added,
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Where should be the define of DGV Properties?

Post by jvierra »

User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: Where should be the define of DGV Properties?

Post by monoeagle »

jvierra wrote:The table column names much match the column "DataPropertyName" or the columns will just be added,
Thanks a lot it runs. =)
This topic is 7 years and 11 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