gpt4 book ai didi

vb.net - Gridview链接按钮单击事件-Windows应用程序

转载 作者:行者123 更新时间:2023-12-02 01:23:12 26 4
gpt4 key购买 nike

如何在vb.net(Windows应用程序)中处理gridview中的linkbutton的点击事件

谢谢

最佳答案

您需要使用 DataGridView.CellClick 事件并检查您是否获得了正确的列索引。您可以通过以下步骤来完成:

Create a new Windows Forms application

Drag a DataGridView onto the screen

In the design time properties, add a column to your grid of type DataGridViewLinkColumn

Make the DataPropertyName property to "Link" (no quotes).

In your forms constructor, paste this code under the call to 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

Consume the DataGridView.CellClick event

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

关于vb.net - Gridview链接按钮单击事件-Windows应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/394989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com