【问题标题】:Launching hyperlink from DataGridViewLinkCell从 DataGridViewLinkCell 启动超链接
【发布时间】:2016-08-06 17:29:36
【问题描述】:

我正在将DataSet 加载到DataGridView 中。数据是本地网络上文件的hyperlink,但我无法获得实际启动文件的链接。我是否必须进入clickevent 并从那里实际启动它?或者有没有我可以在DataGridViewLinkCell 上设置的属性来轻松做到这一点?

谢谢,代码如下。

'dgMain is the DataGridView
dgMain.DataSource = dataSet1.Tables(0)

'Just an example, will format entire column when I'm done
dgMain(10, 1) = New DataGridViewLinkCell

如果我确实走clickevent 路线,我想会是这样,但效果不是很好,但我还没有尝试太多:

Private Sub dgMain_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgMain.CellContentClick
    If e.RowIndex = -1 Then
        Exit Sub
    End If

    If dgMain.Rows(e.RowIndex).Cells(e.ColumnIndex) Is DataGridViewLinkCell Then
        Process.Start(dgMain.Rows(e.RowIndex).Cells(e.ColumnIndex).ToString)
    End If
End Sub

【问题讨论】:

    标签: vb.net datagridview dataset datagridviewlinkcolumn


    【解决方案1】:

    是的,您需要处理点击事件并在代码中启动 URL (Process.Start)

    【讨论】:

    • 哇。真的?。那么首先拥有DataGridViewLinkCell 有什么意义呢?!只是让它变成蓝色并加下划线吗?因为显然我可以从 any 单元格类型的点击事件中调用Process.Start
    • 是的,它只是为内容添加蓝色和下划线,然后在单击后更改颜色:-P 从好的方面来说,您可以在单击后做任何您想做的事情 -加载新表单、更新 WebBrowser 控件等。
    猜你喜欢
    • 2012-10-22
    • 1970-01-01
    • 2020-11-29
    • 2010-09-26
    • 2011-10-23
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多