datagriview按行名和列名获取单元格

时间:2019-07-13 21:13:15

标签: powershell datagridview

我创建了一个datagridview,我想更新单元格value中的一些数据。 当我们牢牢抓住牢房时,我知道该怎么做,但我在换一种方式看。

userlist |1 july 2| july 3 |july 4

Martin
Lukas
franck

I found $datagridviewResults.Columns["july 3"].Index and now I need the same think for the row .

例如,我要为Martin添加10Pm到12PM,日期是7月3日

1 个答案:

答案 0 :(得分:0)

我找到了一些解决方法

    $colunmIndex=$datagridviewResults.Columns["july 3"].Index #I got the column index
    $find = $textboxtest.Text
        $rowcount=$datagridviewResults.RowCount
        $rowindex=-1 # I put -1 because index++ will add +1 and start at 0
        Do
        {
        $rowindex++
        $Rowname= $datagridviewResults[$colunmIndex,$rowindex].value
        }until(($Rowname -like "$find") -or ($rowindex -gt $rowcount))
    #we have both index so now we can edit

    $datagridviewResults[1, $rowindex].Value = 'nice'

#Also if the script can't find the row index , the value at the end will be null .

如果您有更好的解决方案,我仍然很感兴趣。

相关问题