Page 1 of 1

HeaderText exception when not referencing HeaderText

Posted: Fri Nov 29, 2019 3:38 pm
by PaschalIT
- Product, version, build (Please do not use abbreviations, "PS" can mean "PowerShell Studio" as well as "PrimalScript")
Powershell Studio v5.6.170.0

- Specify if you are running a 32 or 64 bit version
64 bit

- Your operating system and if it is 32 or 64 bit.
64 bit

When adding a CellValueChanged event to a DataGridView, I receive an error in the Output window which looks like this:

Code: Select all

: Exception setting "HeaderText": "Cannot index into a null array."
*** PowerShell Script finished. ***
>> Execution time: 00:00:02
>> Script Ended
There is no other context information. I do not have row headers in the DataGridView, and the columns are created in the designer so they are prepopulated before the code runs. This is the code I have within the CellValueChanged event:

Code: Select all

$gridTicketGeneralDIS_CellValueChanged=[System.Windows.Forms.DataGridViewCellEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
	
	if ($_.ColumnIndex -eq 0) {
		if ($gridTicketGeneralDIS.Rows[$_.RowIndex].Cells[0].Style.BackColor -eq 'MistyRose') {
			$gridTicketGeneralDIS.Rows[$_.RowIndex].Cells[0].Style.BackColor = 'White'
		} else {
			$gridTicketGeneralDIS.Rows[$_.RowIndex].Cells[0].Style.BackColor = 'MistyRose'
		}
	}
	
}
There is no reference to HeaderText anywhere, which leads me to believe there is an issue with something running behind the scenes. This is also reinforced by the unusual appearance of the error text, which is white with no reference to lines of code or even which script is producing the error.

Re: HeaderText exception when not referencing HeaderText

Posted: Fri Nov 29, 2019 5:06 pm
by jvierra
Hi,

We need the complete error message and not just the simple text.

Re: HeaderText exception when not referencing HeaderText

Posted: Mon Dec 02, 2019 9:34 am
by PaschalIT
Hi jvierra,

As I said in my original post, there is no "complete error message". What I have posted in the original message is the entirety of what is being shown in the console.

Re: HeaderText exception when not referencing HeaderText

Posted: Mon Dec 02, 2019 9:51 am
by jvierra
You have an error th6at is not caused by the code posted. It is a simplification of an exception that has dropped most of the important parts like the code that caused the error and the line and character number of the issue.

The code you posted cannot cause that error message. There is other code that is causing this.

You need to post a working example that uses the minimum amount of code to demonstrate the issue.

Re: HeaderText exception when not referencing HeaderText

Posted: Mon Dec 09, 2019 12:17 pm
by pjbuckley
I get errors like these every time i forget to create the "column object" i.e.:

Code: Select all

$Column0 			= New-Object System.Windows.Forms.DataGridViewComboBoxColumn
$Column0.Name 		= "StartTime"
$Column0.HeaderText 	= "StartTime"
Omit the first line in that bit of code and i get the same error you do.
or
If you are using a variable to set the "HeaderText" your variable is empty.

Re: HeaderText exception when not referencing HeaderText

Posted: Mon Dec 09, 2019 1:38 pm
by jvierra
It is very difficult to follow your issue. Bits of disconnected code are not helpful.

Without a simple form that illustrates your issue I can soo no way to understand what is happening. Start by creating a new form that has only the failed code and post that. Do not include anything in your example tat references external data. The form needs to be standalone