Thanks for the response
This looks very similar to the syncfusion implementation. I have not actually tried to run yours, but I still don't see how it will work as I want. Specifically, I want to DISPLAY the ComboBox's DisplayMember value in the datagrid, but STORE the ComboBox's ValueMember in the DataGrid's datasource. It appears that your example (and all others that I've looked at), either store AND display the DisplayMember, or store AND display the ValueMember. Here is a listing of what I'm trying to do by intercepting the Paint method. It doesn't actually work, but I THINK I'm on the right track. In particular, have a look at the GetColumnTextAtRow function. Any advice
Public Class DataGridComboBoxColum
Inherits DataGridColumnStyl
' UI constants
Private xMargin As Integer =
Private yMargin As Integer =
Private WithEvents Combo As DataGridComboBo
Private WithEvents tb As TextBo
Private _DisplayMember As Strin
Private _ValueMember As Strin
Private _rowNum As Intege
Private WithEvents _source As CurrencyManage
' Used to track editing stat
Private OldVal As String = String.Empt
Private InEdit As Boolean = Fals
Public Property ComboBox() As DataGridComboBo
Ge
Return Comb
End Ge
Set(ByVal Value As DataGridComboBox
Combo = Valu
End Se
End Propert
Protected Overloads Overrides Sub Paint(ByVal g As Graphics,
ByVal Bounds As Rectangle,
ByVal Source As CurrencyManager,
ByVal RowNum As Integer,
ByVal AlignToRight As Boolean
Dim Text As String = GetText(GetColumnTextAtRow(Source, RowNum)
PaintText(g, Bounds, Text, AlignToRight
End Su
Private Function GetText(ByVal Value As Object) As Strin
If Not Value Is Nothing The
Debug.WriteLine("GetText(" & Value.ToString & ")"
Els
Debug.WriteLine("GetText(Value is Nothing)"
End I
If Value Is System.DBNull.Value Then Return NullTex
If Not Value Is Nothing The
Debug.WriteLine(Value.ToString
Return Value.ToStrin
Els
Debug.WriteLine("Value is Nothing"
Return String.Empt
End I
End Functio
Private Sub PaintText(ByVal g As Graphics,
ByVal Bounds As Rectangle,
ByVal Text As String,
ByVal AlignToRight As Boolean
Debug.WriteLine("PaintText(1)"
Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor
Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor
PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight
End Su
Private Function GetColumnTextAtRow(ByVal Source As CurrencyManager, ByVal RowNum As Integer) As Objec
Dim value As Object = Me.GetColumnValueAtRow(Source, RowNum
Dim dSource As Objec
Dim dr As DataRo
dSource = Combo.DataSourc
If value Is System.DBNull.Value The
Return NullTex
End I
If Not dSource Is Nothing The
If TypeOf dSource Is DataTable The
dSource = CType(dSource, DataTable
If Not dSource.Columns.Contains(Combo.DisplayMember)
OrElse Not dSource.Columns.Contains(Combo.ValueMember) The
Return NullTex
End I
For Each dr In dSource.Row
If value = dr(Combo.ValueMember) The
Return dr(Combo.DisplayMember)
End If
Next
Return NullText
ElseIf TypeOf dSource Is DataView Then
dSource = CType(dSource, DataView)
If Not dSource.Table.Columns.Contains(Combo.DisplayMember) _
OrElse Not dSource.Table.Columns.Contains(Combo.ValueMember) Then
Return value
End If
For Each dr In dSource.Table.Rows
If value = dr(Combo.ValueMember) Then
Return dr(Combo.DisplayMember)
End If
Next
Return NullText
End If
End If
End Function
Private Sub Combo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo.SelectedIndexChanged
tb.Text = CType(sender, ComboBox).Text
End Sub
Public Class DataGridComboBox
Inherits ComboBox
Public Sub New()
MyBase.New()
End Sub
Private _modified As Boolean = False
Public isInEditOrNavigateMode As Boolean = True
Public Property Modified() As Boolean
Get
Return _modified
End Get
Set(ByVal Value As Boolean)
_modified = Value
End Set
End Property
End Class
End Class