我有一个小问题。DataGridViewComboBoxColumn
显示来自ValueMember
而不是来自的值DisplayMember
。网格工作正常,当我从该列中选择某些内容时,我会看到该DisplayMember
值,但是当焦点丢失时,网格会显示ValueMember
. 我有这个代码组合框列:
statusCBoxColumn.DataSource = dt 'datatable with two fields StatusId and StatusText
statusCBoxColumn.DisplayMember = "StatusText" 'is type NVarchar
statusCBoxColumn.ValueMember = "StatusId" 'is type Int
有谁能够帮助我?
编辑:我通过以下方式解决了这个问题:
Private Sub dgv_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv.CellFormatting
If (dgv.Columns(e.ColumnIndex).Name = "statusCBoxColumn") Then
If e.Value & "" > "" Then
Dim s1 As String = e.Value
e.Value = GetData("Select StatusText from Status where ID = " & e.Value).ToString()
End If
End If
End Sub
但我不认为这是最好的解决方案......