Usually you can add fewer columns like this
Code: Select all
$test=1,2,3,4,5,6,7,8,9
$datagridview1.Rows.Add($test)
But if it reaches a dozen columns, I need to write data in new rows in specific columns, such as 1 column, 3 columns, 9 columns, and no data in rows of other columns.
Code: Select all
$test=1,$null,3,$null,$null,$null,$null,$null,9
$datagridview1.Rows.Add($test)
If the column names are incremented and new columns are added or the order of the columns is adjusted, the order of the $test array needs to be reordered in order to write the newly added or reordered columns, which can become very troublesome in the debugging script
Is there a better way?
Similar to
Code: Select all
$datagridview1.Rows[0].Cells['Column1'].Value="1"
$datagridview1.Rows[0].Cells['Column2'].Value="3"
$datagridview1.Rows[0].Cells['Column3'].Value="9"
This way I clearly know that I am writing data to Column1, Column2, Column3 column names