簡體   English   中英

如何更改特定DataGridView單元的值?

[英]How do I change the value of a specific DataGridView Cell?

我一直在嘗試向程序中添加一個功能,該功能允許您使用OpenFileDialog選擇文件(當您雙擊DataGridView單元格時),然后將該單元格的值更改為所選文件的路徑。 我不知道該命令是什么。 我試圖猜測,但我在互聯網上抬頭卻找不到任何東西。

Private Sub dgSound_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgSound.CellDoubleClick

    If e.ColumnIndex = 3 Then 'Index of "file" column
        Dim file As String = ""
        OpenFileDialog1.ShowDialog()
        file = OpenFileDialog1.FileName

        'Contents of cell that was clicked = file          

    End If


End Sub

我將使用CellClick而不是CellContentClick ,如下所示...

  Private Sub dgSound_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgSound.CellClick
    If e.ColumnIndex = 3 Then 'Index of "file" column
      Dim file As String = ""
      OpenFileDialog1.ShowDialog()
      file = OpenFileDialog1.FileName

      'Contents of cell that was clicked = file          
      dgSound.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = file

    End If

  End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM