Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何更改特定DataGridView单元格的值?_Vb.net_Visual Studio 2012_Datagridview - Fatal编程技术网

Vb.net 如何更改特定DataGridView单元格的值?

Vb.net 如何更改特定DataGridView单元格的值?,vb.net,visual-studio-2012,datagridview,Vb.net,Visual Studio 2012,Datagridview,我一直在尝试向我的程序添加一个功能,允许您使用OpenFileDialog(当您双击DataGridView单元格时)选择一个文件,并将该单元格的值更改为所选文件的路径。我不知道命令是什么。我试着猜,在网上查了一下,什么也找不到 Private Sub dgSound_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgSound.CellDoubleClick If e.Column

我一直在尝试向我的程序添加一个功能,允许您使用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

传递给事件的
e
中有一些行/列信息,可以判断单击的是哪一个。@puropoix我知道,但我不知道更改该单元格的具体命令。
dgSound(e.ColumnIndex,e.RowIndex)。Value=“这里有什么”
@puropoix谢谢!我没想到会那么容易。可能是重复的我没有使用CellContentClick,我使用的是CellDoubleClick。谢谢你的回答!