是否有可能在DataGridView
(WinForms-vb.NET)上添加计算列(复杂计算,无法在SQL中计算)?
我希望在ASP.NET中有RowDataBound
GridView
控制事件,但是asp和vb的链接数据的方式太不同了。
答案 0 :(得分:1)
为此,您可以向网格添加未绑定的列:
Dim col As New DataGridViewTextBoxColumn
col.Name = "Unbound"
DataGridView1.Columns.Add(col)
将网格放在VirtualMode中:
DataGridView1.VirtualMode = True
然后使用CellValueNeeded事件的处理程序:
Private Sub CellValueNeeded(sender As System.Object, e As DataGridViewCellValueEventArgs) Handles DataGridView1.CellValueNeeded
If DataGridView1.Columns(e.ColumnIndex).Name = "Unbound" Then
e.Value = "Hi"
End If
End Sub
在上面的处理程序中,我只是将值设置为微不足道的值,但您可以在此处添加任何您喜欢的计算。