简体   繁体   English

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

[英]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.

相关问题 如何在vb中捕获datagridview中的单元格值变化 - How to capture cell value change in datagridview in vb 在单元格值更改时重新排序 Datagridview - Reordering a Datagridview on Cell Value Change DataGridView单元格值更改未发生 - DataGridView Cell Value Change Not Happening 如何检测特定datagridview列的单元格值更改? - VB.NET - How can I detect the cell value changed of a specific datagridview column? - VB.NET 如何在datagridview中更改特定行的颜色,其中单元格值是每天的第一个时间戳? - How can i change color of particular row in datagridview, where a cell value is first timestamp of each day? 如何在Datagridview的特定单元格添加 - How to add at specific Cell of Datagridview Datagridview 单元格值 (Get) 未返回任何内容。 这是什么意思,我该如何解决? - Datagridview Cell Value (Get) Returned Nothing. What does this mean and how do I fix it? DataGridView:如何根据数据源值更改单元格颜色 - DataGridView: How to change cell color depending on data source value DataGridView验证:如何确保一行的每个单元格都包含一个值? - DataGridView validation: How do I ensure that each cell of a row contains a value? 输入有效条目后,在DataGridView单元格中输入无效条目时,如何获取当前单元格值? - When entering an invalid entry in DataGridView Cell after entering a valid entry, how do I get the current cell value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM