HeaderText exception when not referencing HeaderText

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 4 years and 4 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
PaschalIT
Posts: 38
Last visit: Fri Jan 10, 2020 7:38 am

HeaderText exception when not referencing HeaderText

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

Re: HeaderText exception when not referencing HeaderText

Post by jvierra »

Hi,

We need the complete error message and not just the simple text.
PaschalIT
Posts: 38
Last visit: Fri Jan 10, 2020 7:38 am

Re: HeaderText exception when not referencing HeaderText

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

Re: HeaderText exception when not referencing HeaderText

Post 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.
pjbuckley
Posts: 31
Last visit: Mon Jan 06, 2020 12:21 pm

Re: HeaderText exception when not referencing HeaderText

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

Re: HeaderText exception when not referencing HeaderText

Post 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
This topic is 4 years and 4 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