Now I changed to use DataTable to link DataGridView and thought I could change the backcolor of each row. But not sure how do that. Please advise. Thanks.
$dt = New-Object System.Data.DataTable
$dt.Columns.AddRange(@('TIme','Name','Age','Gender'))
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Kate',45,'F')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'John',35,'M')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Bill',58,'M')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Jane',54,'F')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Bill',26,'M')) | Out-Null
$dt.Columns.AddRange(@('TIme','Name','Age','Gender'))
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Kate',45,'F')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'John',35,'M')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Bill',58,'M')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Jane',54,'F')) | Out-Null
$dt.Rows.Add(@((Get-Date).ToString('HH:mm:ss'),'Bill',26,'M')) | Out-Null
$form = New-Object System.Windows.Forms.Form
$form.Size = '500,300'
$form.StartPosition = 'Manual'
$form.Size = '500,300'
$form.StartPosition = 'Manual'
#$DataGridView.Rows.Insert('',(Get-Date).ToString(0,'HH:mm:ss'),'Mary',41,'F')
#$DataGridView.Rows[0].DefaultCellStyle.Backcolor = '100,255,100'
#$DataGridView.Rows[0].DefaultCellStyle.Backcolor = '100,255,100'
$dataGridView= New-Object System.Windows.Forms.DataGridView
$dataGridView.Size = '455,280'
$dataGridView.DataSource = $dt
$dt.DefaultView.Sort = 'Name DESC,Age ASC'
$form.Controls.Add($DataGridView)
$form.ShowDialog()
$form.ShowDialog()