- ERROR: Cannot index into a null array.
- Dem-CellValueChanged.psf (10, 2): ERROR: At Line: 10 char: 2
- ERROR: + $this.Rows[$_.RowIndex].Cells[$_.ColumnIndex].Value = '--- Ch ...
- ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
- ERROR: + FullyQualifiedErrorId : NullArray
- ERROR:
- ERROR: Cannot index into a null array.
- Dem-CellValueChanged.psf (10, 2): ERROR: At Line: 10 char: 2
- ERROR: + $this.Rows[$_.RowIndex].Cells[$_.ColumnIndex].Value = '--- Ch ...
- ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
- ERROR: + FullyQualifiedErrorId : NullArray
- ERROR:
- ERROR: Cannot index into a null array.
- Dem-CellValueChanged.psf (10, 2): ERROR: At Line: 10 char: 2
- ERROR: + $this.Rows[$_.RowIndex].Cells[$_.ColumnIndex].Value = '--- Ch ...
- ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
- ERROR: + FullyQualifiedErrorId : NullArray
- ERROR:
DataGridview Combobox error
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.
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.
Re: DataGridview Combobox error
OK I am sorry but I don't know if you wanted this to have errors to start. Also I am noticing none of your columns are combo boxes. I attached what I am trying to do.
- Attachments
-
- MainForm.psf
- ScriptExample
- (15.1 KiB) Downloaded 65 times
Re: DataGridview Combobox error
Of course, you are getting errors. All of your comboboxes are empty. You cannot use this if the comboboxes have not been populated. You also are starting out with a new automatic row that has all nulls in it.
There is still no way to understand what you are trying to accomplish. Using CellChanged to alter a cell is not a desired method as it is altering a cell that is not stable. You need to consider designing a standard form using standard methods rather than just guessing at how you might do something.
Since we have no idea what it is you are trying to accomplish it is impossible to suggest how you might get your desired outcome.
You need to learn about forms and controls instead of just guessing. So far, every one of your guesses have been completely wrong because you have not learned controls or how the DGV is designed and intended to be used.
As an example, you cannot alter a combobox with a string that is not listed in teh items array.
Play with this and reread the docs until you get a sense of how this works.
There is still no way to understand what you are trying to accomplish. Using CellChanged to alter a cell is not a desired method as it is altering a cell that is not stable. You need to consider designing a standard form using standard methods rather than just guessing at how you might do something.
Since we have no idea what it is you are trying to accomplish it is impossible to suggest how you might get your desired outcome.
You need to learn about forms and controls instead of just guessing. So far, every one of your guesses have been completely wrong because you have not learned controls or how the DGV is designed and intended to be used.
As an example, you cannot alter a combobox with a string that is not listed in teh items array.
Play with this and reread the docs until you get a sense of how this works.
- Attachments
-
- MainForm.psf
- (14.55 KiB) Downloaded 44 times
Re: DataGridview Combobox error
Ok will read up on it. If I am getting what you are saying. I cant add any array to the combo manually and it has to be listed in the items array already. But the attach kind of does what I want. If you look at the code you should be able to see what I am trying to do. I am trying to add two different sets of arrays to the combo box in column 2 depending on one of the choices from column 1 while continuing down the grid with different choices for each row. I will read to see what I am doing wrong. If you can help would be appreciated.
- Attachments
-
- MainForm.psf
- (15.21 KiB) Downloaded 59 times
Re: DataGridview Combobox error
Unfortunately, that is not what the DGV is designed to do. The ComboBoxes are not designed to be loaded for each row as the control is mostly hidden. The best you can do is add to the list in the column definition then select the newly added item.
What I see is that, like most non-windows-programmers you are trying to use forms without any knowledge of how forms are designed and used. It not just a simple system like early HTML controls. WinForms are designed to be data-bound and the DGV is designed to simplify common things we use in a data form. WinForms are not free-form objects. They have a specific purpose which is to support industry standard CUA methods and rules. While you can do things with simple, passive, forms the complex controls are hard to manage when you do not have a design that matches the whole WinForms and CUA model.
This is what CUA specifies and allows: https://en.wikipedia.org/wiki/IBM_Common_User_Access
There is no documentation on MS that tells how to use WinForms with PowerShell in fact it seems that MS is trying to discourage the use of WinForms as it does not match with the new MS design to move everything into the cloud.
My recommendation is to not try to do anything with a control that isn't given as an example in the online documentation or directly accessible as an event, property or method.
Here is a fair sampler of methods that leverage what is basic in many complex controls. I wrote the blog almost 5 years ago, but it is still ok with the exceptions that WordPress keeps screwing up the code examples so download the zip for the correct code.
http://tech-comments.blogspot.com/2017/ ... forms.html
What I see is that, like most non-windows-programmers you are trying to use forms without any knowledge of how forms are designed and used. It not just a simple system like early HTML controls. WinForms are designed to be data-bound and the DGV is designed to simplify common things we use in a data form. WinForms are not free-form objects. They have a specific purpose which is to support industry standard CUA methods and rules. While you can do things with simple, passive, forms the complex controls are hard to manage when you do not have a design that matches the whole WinForms and CUA model.
This is what CUA specifies and allows: https://en.wikipedia.org/wiki/IBM_Common_User_Access
There is no documentation on MS that tells how to use WinForms with PowerShell in fact it seems that MS is trying to discourage the use of WinForms as it does not match with the new MS design to move everything into the cloud.
My recommendation is to not try to do anything with a control that isn't given as an example in the online documentation or directly accessible as an event, property or method.
Here is a fair sampler of methods that leverage what is basic in many complex controls. I wrote the blog almost 5 years ago, but it is still ok with the exceptions that WordPress keeps screwing up the code examples so download the zip for the correct code.
http://tech-comments.blogspot.com/2017/ ... forms.html