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 9 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
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time
Post
by ramses147 » Tue May 30, 2017 12:13 pm
Hi guys,
this code write rows headers number but the first row is '0', is it possible to start to 1 ?
Thanks
$dataGridView .add_RowPostPaint( $dataGridView_RowPostPaint )
$datagridview_RowPostPaint = [ System.Windows.Forms.DataGridViewRowPostPaintEventHandler] {
if ( $dataGridView .Rows[ 0 ] .HeaderCell.Value) {
if ( [ int ] ( $datagridview .Rows[ $_ .RowIndex] .HeaderCell.Value) -ne [ int ] ( $_ .RowIndex) ) {
$dataGridView .Rows[ $_ .RowIndex] .HeaderCell.Value = $_ .RowIndex.ToString( )
}
} else {
# this is to accommodate the first row issue
$dataGridView .Rows[ 0 ] .HeaderCell.Value = '0'
}
}
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 May 30, 2017 12:41 pm
Just change the assignment to add 1 to each row and set the first row to be "1" instead of "0".
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time
Post
by ramses147 » Tue May 30, 2017 1:52 pm
Is this right ?
$dataGridView .Rows[ $_ .RowIndex] .HeaderCell.Value = $_ .RowIndex + 1
}
} else {
$dataGridView .Rows[ 0 ] .HeaderCell.Value = '1'
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time
Post
by ramses147 » Tue May 30, 2017 2:10 pm
i tryed also with this, working but with update flashing
$dataGridView .Rows[ $_ .RowIndex] .HeaderCell.Value = ( $_ .RowIndex + 1 ) .ToString( )
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 May 30, 2017 3:55 pm
ramses147 wrote: any ideas ?
About what? If you did what I posted it will number from 1.
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time
Post
by ramses147 » Wed May 31, 2017 12:15 am
You wrote: Just change the assignment to add 1 to each row and set the first row to be "1" instead of "0".
i wrote this, but here in attachment the results
$dataGridView .Rows[ $_ .RowIndex] .HeaderCell.Value = $_ .RowIndex + 1
}
} else {
$dataGridView .Rows[ 0 ] .HeaderCell.Value = '1'
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 May 31, 2017 1:05 am
I cannot make it any easier.
Code: Select all
$datagridview1_RowPostPaint=[System.Windows.Forms.DataGridViewRowPostPaintEventHandler]{
if($datagridview1.Rows[0].HeaderCell.Value){
if([int]($datagridview1.Rows[$_.RowIndex].HeaderCell.Value - 1) -ne [int]($_.RowIndex)){
$datagridview1.Rows[$_.RowIndex].HeaderCell.Value = ($_.RowIndex + 1).ToString()
}
}else{
# this is to accommodate the first row issue
$datagridview1.Rows[0].HeaderCell.Value = '1'
}
}
ramses147
Posts: 110
Last visit: Tue Dec 05, 2023 7:11 am
Been upvoted: 1 time
Post
by ramses147 » Wed May 31, 2017 1:17 am
Cool, now working right, many thanks !
This topic is 6 years and 9 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