dgv cell click setting column header selection state

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 2 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
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

dgv cell click setting column header selection state

Post by owinsloe »

Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.195
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.19043.0 I have a CellMouseClick event bound to my datagridview so that when I click on any cell the row cell checkbox will be selected\deselected. This works fine during a run through the PSS IDE.

When the script is packaged and I click on a cell, the column header is selected, which I dont want.

The checkbox behaviour is unaffected and works as required, it's just the aesthetics that bug my OCD.

Could you please advise how to avoid the column header being highlighted?

I still need to be able to select the column header for column sort operation.

Thanks
Untitled.jpg
Untitled.jpg (163.83 KiB) Viewed 1626 times
Attachments
Mainform.psf
(73.44 KiB) Downloaded 77 times
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: dgv cell click setting column header selection state

Post by brittneyr »

[Topic was moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dgv cell click setting column header selection state

Post by jvierra »

It is clear that you have added some code somewhere that has caused this. Be sure that all properties are set to default and then test again.
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

Re: dgv cell click setting column header selection state

Post by owinsloe »

The properties and events I have changed are pretty basic but I cant set them to default as then I lose the beaviour that I want so seems a bit pointless.

Properties are;
Properties.jpg
Properties.jpg (77.62 KiB) Viewed 1615 times
The only additional event on dgv is the below to set the CB on a row mouse click;
$datagridview1_CellMouseClick=[System.Windows.Forms.DataGridViewCellMouseEventHandler]{
#Set\unset CB with row select
$Row = $dataGridView1.CurrentCell.RowIndex
$Col = $dataGridView1.CurrentCell.ColumnIndex
if ($Col -eq 0)
{
return
}
else
{
if ($datagridview1.Rows[$row].Cells[0].value -eq $true)
{
$datagridview1.Rows[$row].Cells[0].value = $false
}
else
{
$datagridview1.Rows[$row].Cells[0].value = $true
}
}
}

The real question is that when I use PSS it behaves as I want, when it's packaged it acts differently, so Windows is probably being a @#$%, but I don't know who is at fault.

The rest of the script is interrogating dgv members and doing basic routines outside the dgv.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dgv cell click setting column header selection state

Post by jvierra »

Yes, I can reproduce that when the form is packaged. Since this is an engine issue you will have to open a support request and have Sapien investigate why teh engine changes teh behavior of the control.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: dgv cell click setting column header selection state

Post by Alexander Riedel »

Try to add this to the .config file:

<runtime>
<AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures=false;Switch.UseLegacyAccessibilityFeatures.2=true" />
</runtime>

It appears that this is caused by an update to the .NET framework version.
https://stackoverflow.com/questions/515 ... -selection
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

Re: dgv cell click setting column header selection state

Post by owinsloe »

Thanks Alexander. I have just upgraded PSS and now cant build a package (another post support ticket opened on that one). So I was going to try the config update to just test that it worked.

The only problem with this option (if it works) is that for all my UI packages I uncheck the build of config files as I did not want the additional file distribution to servers. We have over 600 servers in various workgroups and windows domains so restricting what we send out is the most favourable option.

Is there anything that I could add to the script logic that would mimic the config behaviour? ( I'm assuming not :( )
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

Re: dgv cell click setting column header selection state

Post by owinsloe »

ahhh, just read the link and it looks like I need something like;
$dataGridView1.ColumnHeadersDefaultCellStyle.SelectionBackColor = $dataGridView1.ColumnHeadersDefaultCellStyle.BackColor;

I'll play with that once I have a fix to my packaging problem
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

Re: dgv cell click setting column header selection state

Post by owinsloe »

Alexander
adding $dataGridView1.ColumnHeadersDefaultCellStyle.SelectionBackColor = $dataGridView1.ColumnHeadersDefaultCellStyle.BackColor to the Mainform_Load corrected the behaviour. Maybe worth posting a note to a suitable coding forum so other punters are aware. Thanks for the clue. Cheers
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: dgv cell click setting column header selection state

Post by Alexander Riedel »

You should not exclude the .config file. It is an essential part of .NET applications and generally required. You may have degraded runtime compatibility and screen resolution issues without it. I know that there is a large crowd that insists on 'everything should be a single executable', but that is really a thing of the past. Modern applications, specially going forward, consist of a multitude of files in one folder, potentially with subfolders containing resources for multiple languages.
I understand that each environment is unique and you may fight the 'man' there :D, but ...

Your solution just fudges the colors when the column header is selected, which is not something we would recommend in general.
The proper solution is to adapt the accessibility options in the config file, if so desired.
It would give a user with a visual impairment the option to switch back to the newer UI style for accessibility support by modifying the .config file.
By removing the config file or by simply overriding selection background colors you deny users that option.

I do of course not know if any of this is important to your users, but I have to point that out for everyone else reading this post in the future :D
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 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