[英]How do I change the value of a specific DataGridView Cell?
I've been trying to add a feature to my program that allows you to choose a file using OpenFileDialog (when you double click on a DataGridView cell) and change the value of that cell to the path of the file you chose. 我一直在尝试向程序中添加一个功能,该功能允许您使用OpenFileDialog选择文件(当您双击DataGridView单元格时),然后将该单元格的值更改为所选文件的路径。 I have no idea what the command is to do that.
我不知道该命令是什么。 I've tried to guess and I looked up on the internet and couldn't find anything.
我试图猜测,但我在互联网上抬头却找不到任何东西。
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
I'd use CellClick
rather than CellContentClick
as follows... 我将使用
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.