DefaultCellStyle should not be shared between DataGridViews

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

Re: DefaultCellStyle should not be shared between DataGridViews

Post by jvierra »

Ok. Forced second control to generate separate view. The control, for your purposes, seems to work correctly.

Moved the code to Load and it runs correctly by just copying the code for one two a second and renaming the view.

In Load:

Code: Select all

    $System_Windows_Forms_DataGridViewCellStyle_2 = New-Object 'System.Windows.Forms.DataGridViewCellStyle'
	$System_Windows_Forms_DataGridViewCellStyle_2.Alignment = 'MiddleLeft'
	$System_Windows_Forms_DataGridViewCellStyle_2.BackColor = 'Window'
	$System_Windows_Forms_DataGridViewCellStyle_2.Font = 'Microsoft Sans Serif, 8.25pt'
	$System_Windows_Forms_DataGridViewCellStyle_2.ForeColor = 'ControlText'
	$System_Windows_Forms_DataGridViewCellStyle_2.SelectionBackColor = 'Red'
	$System_Windows_Forms_DataGridViewCellStyle_2.SelectionForeColor = 'HighlightText'
	$System_Windows_Forms_DataGridViewCellStyle_2.WrapMode = 'False'
	$dgvOwner.DefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle_2


	$System_Windows_Forms_DataGridViewCellStyle_1 = New-Object 'System.Windows.Forms.DataGridViewCellStyle'
	$System_Windows_Forms_DataGridViewCellStyle_1.Alignment = 'MiddleLeft'
	$System_Windows_Forms_DataGridViewCellStyle_1.BackColor = 'Window'
	$System_Windows_Forms_DataGridViewCellStyle_1.Font = 'Microsoft Sans Serif, 8.25pt'
	$System_Windows_Forms_DataGridViewCellStyle_1.ForeColor = 'ControlText'
	$System_Windows_Forms_DataGridViewCellStyle_1.SelectionBackColor = 'ForestGreen'
	$System_Windows_Forms_DataGridViewCellStyle_1.SelectionForeColor = 'HighlightText'
	$System_Windows_Forms_DataGridViewCellStyle_1.WrapMode = 'False'
	$dgvEquipment.DefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle_1

Which is pretty much identical to what you have posted.
This topic is 6 years and 1 month 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