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
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm
Post
by lontru » Tue Nov 05, 2019 1:06 am
Have build a little tool for viewing logs but have little issue
How do i not open the log when I double click the header when i sort by date.
Have recordet a gif for showing the issue
using datatable for the datagridview
Is there a way to presort so lasted LASTWritetime is presorted after date.
the code i use for the double click event is:
Code: Select all
$datagridviewLogs_CellContentDoubleClick = [System.Windows.Forms.DataGridViewCellEventHandler]{
$script:SelectedLogfile = $datagridviewLogs.SelectedRows[0].Cells[0].Value
$cmtrace0 = "$env:windir\system32\CMTrace.exe"
if (Test-Path $cmtrace0 -PathType Leaf)
{
$cmtrace = $cmtrace0
}
if (Test-Path $cmtrace -PathType Leaf)
{
. "$cmtrace" ""$logpath\$SelectedLogfile""
Write-Host "$target Open: $logpath\$SelectedLogfile"
}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Tue Nov 05, 2019 3:00 am
What does the GIF have to do with sorting the grid?
Use the correct event to detect the cell click event.
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm
Post
by lontru » Tue Nov 05, 2019 4:04 am
when i double click on the header "lastwritetime" it open the selected row. I dont want that to happen.
the gif is to show how the form behave when i double click the header in the grid "lastwritetime"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Tue Nov 05, 2019 5:42 am
You must have an issue with the header or with your code. Be sure you didn't add the event to the header clicks.
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm
Post
by lontru » Tue Nov 05, 2019 6:21 am
I have these line to prevent file form loading as work around.
$datagridviewLogs_ColumnHeaderMouseDoubleClick = [System.Windows.Forms.DataGridViewCellMouseEventHandler]{
$datagridviewLogs.CurrentCell = $null
}
$datagridviewLogs_ColumnHeaderMouseClick = [System.Windows.Forms.DataGridViewCellMouseEventHandler]{
$datagridviewLogs.CurrentCell = $null
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Tue Nov 05, 2019 9:56 am
Ok - had some time to try to reproduce your issue. Here is how we guard against column header clicks. First use CellDoubleClick and add a check the the row is not -1.
Code: Select all
$datagridviewResults_CellDoubleClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
if($_.RowIndex -ge 0){Write-Host 'Clicked'}
}
Any header cell that is double clicked will have a RowIndex less than 0.
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm
Post
by lontru » Tue Nov 05, 2019 11:56 pm
I have inserted your code but the behavior is wierd
the if block should only run if rowindex is greater then -1 but it still run??
I double click on the header - recording show wierd mouse placement.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Wed Nov 06, 2019 12:04 am
Please skip the GIFs as they are not readable and of no help.
You have other things in your code that6 are causing issues.
I have no way of knowing what code you are using. Pictures are of no help.
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm
Post
by lontru » Wed Nov 06, 2019 2:25 am
this works for now,
Code: Select all
$datagridviewLogs_CellDoubleClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
if ($($_.RowIndex) -gt -1)
{
$script:SelectedLogfile = $datagridviewLogs.SelectedRows[0].Cells[0].Value
$cmtrace2 = "$env:windir\system32\CMTrace.exe"
if (Test-Path $cmtrace2 -PathType Leaf)
{
$cmtrace = $cmtrace2
}
if (Test-Path $cmtrace -PathType Leaf)
{
#. "$cmtrace" ""$logpath\$SelectedLogfile""
Write-Host "$target Open: $logpath\$SelectedLogfile"
}
}
}
$datagridviewLogs_ColumnHeaderMouseDoubleClick=[System.Windows.Forms.DataGridViewCellMouseEventHandler]{
$datagridviewLogs.CurrentCell = $null
}
$datagridviewLogs_ColumnHeaderMouseClick=[System.Windows.Forms.DataGridViewCellMouseEventHandler]{
$datagridviewLogs.CurrentCell = $null
}
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