想做一个DataGridView在同一列既能显示字符串也能LinkText.
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
With DGV
.Columns.Add("Test1", "Test1")
.Columns.Add("Test2", "Test2")
.Rows.Add()
.Rows(0).Cells(0).Value = "ttt"
.Rows(0).Cells(1).Value = "fff"
.Rows(1).Cells(0).Value = "AAA"
.Rows(1).Cells(1).Value = "111"
End With
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
With DGV
.Columns.RemoveAt(1)
.Columns.Insert(1, New DataGridViewColumn)
Dim cell1 As New DataGridViewLinkColumn
cell1.Text = "test"
Dim cell2 As New DataGridViewTextBoxColumn
cell2.Text = "TEST"
.Rows(0).Cells(1) = cell1
.Rows(1).Cells(1) = cell2
End With
End Sub
但是报DataGridViewTextBoxColumn无法转换为DataGridViewColumn,有没有可行的办法呢?