我在VB中有一些循环遍历gridview的行并且正在检查某个列的值的代码,我在if语句中编写了一些代码,在单元格内创建了一个可点击的标签,用于我已经编写了一些代码可以创建我的标签,但是我不太确定如何在row.Cells(8)中创建它。
我想知道是否可以得到一些帮助我应该怎么做?...
这是我的代码:
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim row = GridView1.Rows(i)
Dim rowHeaderCell = row.Cells(8)
If rowHeaderCell.Text = " " Then
Dim lbl As New Label
lbl.Size = New System.Drawing.Size(159, 23)
lbl.Location =
lbl.Text = "label text goes here"
Me.Controls.Add(lbl)
End If
Next
提前谢谢!
答案 0 :(得分:0)
要制作可点击标签,请将列的类型更改为:[DataGridViewLinkColumn]
这里是用LBL值替换空单元格值的代码:
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(8).Value.Trim = "" Then
Dim lbl As String
lbl = "label text goes here "
GridView1.Rows(i).Cells(8).Value = lbl
End If
Next