Vb.net 事件上的Openfile

Vb.net 事件上的Openfile,vb.net,datagridview,datagridviewbuttoncolumn,Vb.net,Datagridview,Datagridviewbuttoncolumn,我正在用VB.Net编程(完全是新手)。我有一个DataGridView,其中包括一个存储特定文档的文件路径。我已经在DataGridView中添加了DataGridViewButtonColumn,但是我不知道如何使用按钮打开文件 很抱歉,我没有代码可以作为我陷入困境的起点 提前感谢,很抱歉,我第一次没有读清楚这篇文章,也没有解释清楚我的代码,所以被删除了。这将使用contentclick事件 Dim Filetext As String = "" 'At start of the class

我正在用VB.Net编程(完全是新手)。我有一个DataGridView,其中包括一个存储特定文档的文件路径。我已经在DataGridView中添加了DataGridViewButtonColumn,但是我不知道如何使用按钮打开文件

很抱歉,我没有代码可以作为我陷入困境的起点


提前感谢,

很抱歉,我第一次没有读清楚这篇文章,也没有解释清楚我的代码,所以被删除了。这将使用contentclick事件

Dim Filetext As String = "" 'At start of the class to make it available to the whole class

Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim FilePathColumn As Integer = 0 'File path is in Column 0
Dim ButtonColumn As Integer = 1 'Column buttons are in
Dim RowClicked As Integer = e.RowIndex 'This gets the row that you clicked the button in

If e.ColumnIndex = ButtonColumn Then 'Make sure you clicked a button
    Dim FILE_PATH As String = DataGridView1.Rows(RowClicked).Cells(FilePathColumn).ToString 'Get the path to the file
    If System.IO.File.Exists(FILE_PATH) Then 'Make sure file exists
        Filetext = System.IO.File.ReadAllText(FILE_PATH) 'Save file to a variable

        'OR

        Process.Start(FILE_PATH) 'To open it
    End If
End If
End Sub

你可以去掉其中的大部分台词,但我这样写是为了解释它是如何工作的

你的问题缺乏细节。文件路径是否在特定列中?是否有多个路径不同的行?请展示您是如何使用数据创建DataGridView的…我向Codexer道歉。是的,文件路径位于特定列中。它被命名为InvoiceFileLocation。关于第二个问题,是的,有多行具有不同的路径。谢谢你回答我的问题。在谷歌搜索这篇文章的时候,有很多点击率。你试过其中任何一种吗?我试过搜索DataGridViewButtonColumn以及如何使用DataGridViewButtonColumn打开文件,但我似乎得到了C#答案。我将根据从上述问题中获得的信息优化搜索。您可以利用
CellContentClick
事件。然后可以使用
Process.Start
并将当前行/列数据(filelath)作为Process.Start的参数传递