Vb.net 如何更改特定DataGridView单元格的值?
我一直在尝试向我的程序添加一个功能,允许您使用OpenFileDialog(当您双击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
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。谢谢你的回答!