您需要使用 DataGridView.CellClick 事件并检查是否获得了正确的列索引。您可以按照以下步骤进行操作:
创建新的 Windows 窗体应用程序
将 DataGridView 拖到屏幕上
在设计时属性中,将一列添加到 DataGridViewLinkColumn 类型的网格中
将 DataPropertyName 属性设置为“Link”(无引号)。
在表单构造函数中,将此代码粘贴到对 InitializeComponent 的调用下:
哦,是的,您正在 VB.NET 中执行此操作,所以它会是:
Dim data As New DataTable()
data.Columns.Add(New DataColumn("Link", Type.GetType("System.String")))
Dim newRow As DataRow = data.NewRow()
newRow("Link") = "http://www.stackoverflow.com"
data.Rows.Add(newRow)
DataGridView1.DataSource = data
Run Code Online (Sandbox Code Playgroud)
使用 DataGridView.CellClick 事件
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If (e.ColumnIndex = 0) Then
Dim link As String = DataGridView1(e.ColumnIndex, e.RowIndex).Value.ToString()
System.Diagnostics.Process.Start(link)
End If
End Sub
Run Code Online (Sandbox Code Playgroud)