我的应用程序是VB中的一个windows窗体应用程序。
我的申请中有DataGridView。当我设计DataGridViewLinkColumn时,第七列被定义为DataGridView。我的应用程序从表中读取链接,Grid正确地显示它。
我不想让我的用户看到链接,我想让他们看到一个像“点击这里访问”这样的句子,但我无法做到。
第二,当我单击链接时,什么都不会发生。我知道我必须在CellContentClick事件中处理这个问题,但是我不知道如何调用指向链接的默认浏览器。
提前谢谢。
发布于 2015-01-11 12:36:55
DataGridViewLinkColumn中没有直接属性,它将显示文本和url分隔开来。
要实现您的目标,您需要处理两个事件CellFormatting和CellContentClick。订阅这些事件。
在CellFormatting事件处理程序中,将格式化的值更改为Click here to visit。必须将标志FormattingApplied设置为True,因为这样可以防止进一步格式化该值。
Private Sub dataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
If e.ColumnIndex = 'link column index Then
e.Value = "Click here to visit";
e.FormattingApplied = True;
End If
End Sub若要在默认浏览器中打开链接,请使用Process类并将url作为参数传递给Start方法。将代码放入CellContentClick事件处理程序中。
Private Sub dataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
If e.ColumnIndex = 'link column index Then
Process.Start(dataGridView1(e.ColumnIndex, e.RowIndex).Value.ToString());
End If
End Subhttps://stackoverflow.com/questions/27886122
复制相似问题