Hi, I have a tough one..

I have a datagrid that is bound to a typed dataset the following way

Dim ds as New MyDataSe

Datagrid.Datasource = d
Datagrid.DataMembre = "BonReception" 'A datatable from my datase

In that datagrid I have to combobox column (they come from a class I have made) and the combobox are bound like this

ComboBoxColumn.ComboBox.DataSource = d
ComboBoxColumn.ComboBox.DisplayMember = "Intervenant.TypeIntervenant" 'Another datatable from my datase
ComboBoxColumn.ComboBox.ValueMember = "Intervenant.ID
ComboBoxColumn.ComboBox.DataBindings.Add("SelectedValue", ds, "BonReception.TypeIntervenantID"

The second combobox column's combobox use a data relation between the table Intervenant and IntervenantDetai

ComboBoxColumn.ComboBox.DataSource = d
ComboBoxColumn.ComboBox.DisplayMember = "Intervenant.IntervenantIntervenantDetail.Intervenant" ComboBoxColumn.ComboBox.ValueMember = "Intervenant.IntervenantIntervenantDetail.ID
ComboBoxColumn.ComboBox.DataBindings.Add("SelectedValue", ds, "BonReception.IntervenantDetailID"

The comboboxes in each column behave as expected, if you select a TypeIntervenant in the first combobox, the second combobox only displays the Intervenant that match the selected TypeIntervenant in the first combobox

The problem is this,

the data is displayed in the first combobox column, but only in the first row of the second combobox column. If I click in the first column on the second row then in the second column the first row will go blank and the second row will display it's value. If I click in the second column at any row the combobox shows up with the right value for that row

If I remove the data relation between table Intervenant and IntervenantDetail, the data is displayed correctly and everything behave as expected. But I don't have the relation between the two combobox columns and I need that

Here is the code for my ComboBoxColumn Class

Public Class DataGridFormattableComboBoxColum
Inherits DataGridColumnStyl

Private isEditing As Boolea
Private isReadOnly As Boolea
Private _cm As CurrencyManage
Private _RowNum As Intege

Private WithEvents _ComboBox As New NoTabComboBo

Public Event SetCellFormat As FormatCellEventHandle
Public Event CurrentCellDataChanged(ByVal MappingName As String, ByVal Data As Object

Public Sub New(
MyBase.New(

ComboBox.Visible = Fals
End Su

Public Property ComboBox() As NoTabComboBo
Ge
Return _ComboBo
End Ge
Set(ByVal Value As NoTabComboBox
_ComboBox = Valu
End Se
End Propert

Protected Overrides Sub Abort(ByVal rowNum As Integer
isEditing = Fals
Invalidate(
End Su

Protected Overrides Function Commit(ByVal dataSource As CurrencyManager, ByVal rowNum As Integer) As Boolea
ComboBox_Leave(Nothing, Nothing
Return Tru
End Functio

Protected Overloads Overrides Sub Edit(ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle,
ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean
Dim value As Strin

If Me.isEditing The
Exit Su
End I

If MyBase.ReadOnly The
Exit Su
End I

_cm = sourc
_RowNum = rowNu

If IsDBNull(GetColumnValueAtRow([source], rowNum)) The
value = MyBase.NullTex

If ComboBox.DataSource Is Nothing And Not ComboBox.Items.Contains(value) The
ComboBox.Items.Insert(0, value
End I
Els
value = CType(GetColumnValueAtRow([source], rowNum), String
End I

If cellIsVisible The
ComboBox.Bounds = New Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height - 2

ComboBox.Text = valu
ComboBox.Visible = Tru
ComboBox.Focus(
Els
ComboBox.Text = valu
ComboBox.Visible = Fals
End I
End Su

Protected Overrides Function GetPreferredSize(ByVal g As Graphics, ByVal value As Object) As Siz
Return New Size(100, ComboBox.PreferredHeight + 1
End Functio

Protected Overrides Function GetMinimumHeight() As Integer
Return ComboBox.PreferredHeight + 1
End Function

Protected Overrides Function GetPreferredHeight(ByVal g As Graphics, ByVal value As Object) As Integer
Return ComboBox.PreferredHeight + 1
End Function

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer)
Paint(g, bounds, [source], rowNum, False)
End Sub

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)
Paint(g, bounds, [source], rowNum, Brushes.Red, Brushes.Blue, alignToRight)
End Sub

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)
Dim str As Object
Dim rect As Rectangle = bounds

Dim e As DataGridFormatCellEventArgs

e = New DataGridFormatCellEventArgs(source, rowNum, Me.MappingName, Me.DataGridTableStyle.DataGrid.Font, backBrush, foreBrush)

RaiseEvent SetCellFormat(Me, e)

str = GetColumnValueAtRow([source], rowNum)

If IsDBNull(str) Then
str = MyBase.NullText
End If

If Not e.UseBaseClassDrawing Then
g.FillRectangle(e.BackBrush, rect)
Else
g.FillRectangle(backBrush, rect)
End If

rect.Offset(0, 2)
rect.Height -= 2

Try
If Not e.UseBaseClassDrawing Then
g.DrawString(str, e.TextFont, e.ForeBrush, RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))
Else
g.DrawString(str, Me.DataGridTableStyle.DataGrid.Font, foreBrush, RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid)
MyBase.SetDataGridInColumn(value)
If Not (ComboBox.Parent Is Nothing) Then
ComboBox.Parent.Controls.Remove(ComboBox)
End If
If Not (value Is Nothing) Then
value.Controls.Add(ComboBox)
End If
End Sub

Private Sub ComboBox_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ComboBox.SelectedValueChanged
If ComboBox.Modified Then
Me.isEditing = True
MyBase.ColumnStartedEditing(ComboBox)
End If
End Sub

Protected Overrides Function GetColumnValueAtRow(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
If Not Me.ComboBox.DataSource Is Nothing Then
Try
Dim obj As Object = MyBase.GetColumnValueAtRow(source, rowNum)
Dim i As Integer
Dim DataMember As String
Dim ValueColName As String
Dim DisplayColName As String
Dim cm As CurrencyManager
Dim dView As DataView

If Me.ComboBox.DisplayMember.IndexOf(".") > -1 Then
DataMember = Me.ComboBox.DisplayMember.Substring(0, Me.ComboBox.DisplayMember.LastIndexOf("."))
DisplayColName = Me.ComboBox.DisplayMember.Substring(Me.ComboBox.DisplayMember.LastIndexOf(".") + 1)
Else
DisplayColName = Me.ComboBox.DisplayMember
End If

If Me.ComboBox.ValueMember.IndexOf(".") > -1 Then
ValueColName = Me.ComboBox.ValueMember.Substring(Me.ComboBox.ValueMember.LastIndexOf(".") + 1)
Else
ValueColName = Me.ComboBox.ValueMember
End If

If Me.ComboBox.DataSource.GetType.ToString.EndsWith("dsBonReception") Then
cm = CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource, DataMember), CurrencyManager)
Else
cm = CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource), CurrencyManager)
End If

dView = CType(cm.List, DataView)

For i = 0 To dView.Count - 1
If Not IsDBNull(obj) AndAlso Not IsDBNull(dView.Item(i).Item(ValueColName)) Then
If obj = 340 And dView.Item(i).Item(ValueColName) = 340 Then
Dim t As String
t = ""
End If
End If
If obj.Equals(dView.Item(i).Item(ValueColName)) Then
Exit For
End If
Next

If i < dView.Count Then
Return dView.Item(i).Item(DisplayColName)
End If

Return DBNull.Value
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Return MyBase.GetColumnValueAtRow(source, rowNum)
End If
End Function

Protected Overrides Sub SetColumnValueAtRow(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal value As Object)
If Not Me.ComboBox.DataSource Is Nothing Then
Try
Dim s As Object = value
Dim DataMember As String
Dim ValueColName As String
Dim DisplayColName As String
Dim cm As CurrencyManager
Dim i As Integer
Dim dView As DataView

If Me.ComboBox.DisplayMember.IndexOf(".") > -1 Then
DataMember = Me.ComboBox.DisplayMember.Substring(0, Me.ComboBox.DisplayMember.LastIndexOf("."))
DisplayColName = Me.ComboBox.DisplayMember.Substring(Me.ComboBox.DisplayMember.LastIndexOf(".") + 1)
Else
DisplayColName = Me.ComboBox.DisplayMember
End If

If Me.ComboBox.ValueMember.IndexOf(".") > -1 Then
ValueColName = Me.ComboBox.ValueMember.Substring(Me.ComboBox.ValueMember.LastIndexOf(".") + 1)
Else
ValueColName = Me.ComboBox.ValueMember
End If

If Me.ComboBox.DataSource.GetType.ToString.EndsWith("dsBonReception") Then
cm = CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource, DataMember), CurrencyManager)
Else
cm = CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource), CurrencyManager)
End If

dView = CType(cm.List, DataView)

For i = 0 To dView.Count - 1
If s.Equals(dView.Item(i).Item(ValueColName)) Then
Exit For
End If
Next

If i < dView.Count Then
If source.Position = rowNum Then
MyBase.SetColumnValueAtRow(source, rowNum, dView.Item(i).Item(ValueColName))
End If
Else
If source.Position = rowNum Then
MyBase.SetColumnValueAtRow(source, rowNum, DBNull.Value)
End If
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MyBase.SetColumnValueAtRow(source, rowNum, value)
End If
End Sub

Private Sub ComboBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ComboBox.Leave
If Not isEditing Then
ComboBox.Hide()
Exit Sub
End If

isEditing = False

Try
Dim value As Object = ComboBox.SelectedValue

If Not value Is Nothing Then
SetColumnValueAtRow(_cm, _RowNum, value)
RaiseEvent CurrentCellDataChanged(MyBase.MappingName, value)
Else
EnterNullValue()
RaiseEvent CurrentCellDataChanged(MyBase.MappingName, DBNull.Value)
End If
Catch
End Try

Invalidate()
ComboBox.Hide()
End Sub

'
' ComboBox class removing the tab key
'
Public Class NoTabComboBox
Inherits ComboBox

Private pModified As Boolean
Private KeyPressed As Boolean
Private MouseClicked As Boolean

Sub New()
pModified = False
KeyPressed = False
MouseClicked = False
End Sub

Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub

Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList)
MyBase.SetItemsCore(items)
End Sub

Protected Overrides Function ProcessKeyMessage(ByRef m As System.Windows.Forms.Message) As Boolean
If m.Msg = &H101 Then '&H101 = WM_KEYUP
If m.WParam.ToInt32 = 9 Then '9 = TABKEY
Return True
End If
End If
Return MyBase.ProcessKeyMessage(m)
End Function

Public ReadOnly Property Modified() As Boolean
Get
Modified = pModified
End Get
End Property

Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MouseClicked = True
End Sub

Protected Overrides Sub OnSelectedValueChanged(ByVal e As System.EventArgs)
If MouseClicked Or KeyPressed Then
pModified = True
MouseClicked = False
KeyPressed = False
Else
pModified = False
End If

MyBase.OnSelectedValueChanged(e)
End Sub

Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Char.IsLetterOrDigit(e.KeyChar) Then
KeyPressed = True
End If

MyBase.OnKeyPress(e)
End Sub
End Class
End Class

Re: Datagrid and Bound ComboBox Columns by Richard

Richard
Fri Feb 27 17:10:51 CST 2004

Put this above the form load

Dim ds as New MyDataSet

"Mike Hardy" <anonymous@discussions.microsoft.com> wrote in message
news:2A707F29-7B96-4C28-99E3-5D6659FAFFCC@microsoft.com...
> Hi, I have a tough one...
>
> I have a datagrid that is bound to a typed dataset the following way.
>
> Dim ds as New MyDataSet
>
> Datagrid.Datasource = ds
> Datagrid.DataMembre = "BonReception" 'A datatable from my dataset
>
> In that datagrid I have to combobox column (they come from a class I have
made) and the combobox are bound like this.
>
> ComboBoxColumn.ComboBox.DataSource = ds
> ComboBoxColumn.ComboBox.DisplayMember = "Intervenant.TypeIntervenant"
'Another datatable from my dataset
> ComboBoxColumn.ComboBox.ValueMember = "Intervenant.ID"
> ComboBoxColumn.ComboBox.DataBindings.Add("SelectedValue", ds,
"BonReception.TypeIntervenantID")
>
> The second combobox column's combobox use a data relation between the
table Intervenant and IntervenantDetail
>
> ComboBoxColumn.ComboBox.DataSource = ds
> ComboBoxColumn.ComboBox.DisplayMember =
"Intervenant.IntervenantIntervenantDetail.Intervenant"
ComboBoxColumn.ComboBox.ValueMember =
"Intervenant.IntervenantIntervenantDetail.ID"
> ComboBoxColumn.ComboBox.DataBindings.Add("SelectedValue", ds,
"BonReception.IntervenantDetailID")
>
> The comboboxes in each column behave as expected, if you select a
TypeIntervenant in the first combobox, the second combobox only displays the
Intervenant that match the selected TypeIntervenant in the first combobox.
>
> The problem is this,
>
> the data is displayed in the first combobox column, but only in the first
row of the second combobox column. If I click in the first column on the
second row then in the second column the first row will go blank and the
second row will display it's value. If I click in the second column at any
row the combobox shows up with the right value for that row.
>
> If I remove the data relation between table Intervenant and
IntervenantDetail, the data is displayed correctly and everything behave as
expected. But I don't have the relation between the two combobox columns and
I need that.
>
> Here is the code for my ComboBoxColumn Class.
>
> Public Class DataGridFormattableComboBoxColumn
> Inherits DataGridColumnStyle
>
> Private isEditing As Boolean
> Private isReadOnly As Boolean
> Private _cm As CurrencyManager
> Private _RowNum As Integer
>
> Private WithEvents _ComboBox As New NoTabComboBox
>
> Public Event SetCellFormat As FormatCellEventHandler
> Public Event CurrentCellDataChanged(ByVal MappingName As String, ByVal
Data As Object)
>
> Public Sub New()
> MyBase.New()
>
> ComboBox.Visible = False
> End Sub
>
> Public Property ComboBox() As NoTabComboBox
> Get
> Return _ComboBox
> End Get
> Set(ByVal Value As NoTabComboBox)
> _ComboBox = Value
> End Set
> End Property
>
> Protected Overrides Sub Abort(ByVal rowNum As Integer)
> isEditing = False
> Invalidate()
> End Sub
>
> Protected Overrides Function Commit(ByVal dataSource As CurrencyManager,
ByVal rowNum As Integer) As Boolean
> ComboBox_Leave(Nothing, Nothing)
> Return True
> End Function
>
> Protected Overloads Overrides Sub Edit(ByVal [source] As
CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle, _
> ByVal [readOnly] As Boolean,
ByVal instantText As String, ByVal cellIsVisible As Boolean)
> Dim value As String
>
> If Me.isEditing Then
> Exit Sub
> End If
>
> If MyBase.ReadOnly Then
> Exit Sub
> End If
>
> _cm = source
> _RowNum = rowNum
>
> If IsDBNull(GetColumnValueAtRow([source], rowNum)) Then
> value = MyBase.NullText
>
> If ComboBox.DataSource Is Nothing And Not
ComboBox.Items.Contains(value) Then
> ComboBox.Items.Insert(0, value)
> End If
> Else
> value = CType(GetColumnValueAtRow([source], rowNum), String)
> End If
>
> If cellIsVisible Then
> ComboBox.Bounds = New Rectangle(bounds.X, bounds.Y, bounds.Width,
bounds.Height - 2)
>
> ComboBox.Text = value
> ComboBox.Visible = True
> ComboBox.Focus()
> Else
> ComboBox.Text = value
> ComboBox.Visible = False
> End If
> End Sub
>
> Protected Overrides Function GetPreferredSize(ByVal g As Graphics, ByVal
value As Object) As Size
> Return New Size(100, ComboBox.PreferredHeight + 1)
> End Function
>
> Protected Overrides Function GetMinimumHeight() As Integer
> Return ComboBox.PreferredHeight + 1
> End Function
>
> Protected Overrides Function GetPreferredHeight(ByVal g As Graphics,
ByVal value As Object) As Integer
> Return ComboBox.PreferredHeight + 1
> End Function
>
> Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As
Integer)
> Paint(g, bounds, [source], rowNum, False)
> End Sub
>
> 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)
> Paint(g, bounds, [source], rowNum, Brushes.Red, Brushes.Blue,
alignToRight)
> End Sub
>
> Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
bounds As Rectangle, ByVal [source] As CurrencyManager, ByVal rowNum As
Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
alignToRight As Boolean)
> Dim str As Object
> Dim rect As Rectangle = bounds
>
> Dim e As DataGridFormatCellEventArgs
>
> e = New DataGridFormatCellEventArgs(source, rowNum, Me.MappingName,
Me.DataGridTableStyle.DataGrid.Font, backBrush, foreBrush)
>
> RaiseEvent SetCellFormat(Me, e)
>
> str = GetColumnValueAtRow([source], rowNum)
>
> If IsDBNull(str) Then
> str = MyBase.NullText
> End If
>
> If Not e.UseBaseClassDrawing Then
> g.FillRectangle(e.BackBrush, rect)
> Else
> g.FillRectangle(backBrush, rect)
> End If
>
> rect.Offset(0, 2)
> rect.Height -= 2
>
> Try
> If Not e.UseBaseClassDrawing Then
> g.DrawString(str, e.TextFont, e.ForeBrush,
RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))
> Else
> g.DrawString(str, Me.DataGridTableStyle.DataGrid.Font, foreBrush,
RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))
> End If
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> End Sub
>
> Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid)
> MyBase.SetDataGridInColumn(value)
> If Not (ComboBox.Parent Is Nothing) Then
> ComboBox.Parent.Controls.Remove(ComboBox)
> End If
> If Not (value Is Nothing) Then
> value.Controls.Add(ComboBox)
> End If
> End Sub
>
> Private Sub ComboBox_SelectedValueChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles _ComboBox.SelectedValueChanged
> If ComboBox.Modified Then
> Me.isEditing = True
> MyBase.ColumnStartedEditing(ComboBox)
> End If
> End Sub
>
> Protected Overrides Function GetColumnValueAtRow(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
> If Not Me.ComboBox.DataSource Is Nothing Then
> Try
> Dim obj As Object = MyBase.GetColumnValueAtRow(source, rowNum)
> Dim i As Integer
> Dim DataMember As String
> Dim ValueColName As String
> Dim DisplayColName As String
> Dim cm As CurrencyManager
> Dim dView As DataView
>
> If Me.ComboBox.DisplayMember.IndexOf(".") > -1 Then
> DataMember = Me.ComboBox.DisplayMember.Substring(0,
Me.ComboBox.DisplayMember.LastIndexOf("."))
> DisplayColName =
Me.ComboBox.DisplayMember.Substring(Me.ComboBox.DisplayMember.LastIndexOf(".
") + 1)
> Else
> DisplayColName = Me.ComboBox.DisplayMember
> End If
>
> If Me.ComboBox.ValueMember.IndexOf(".") > -1 Then
> ValueColName =
Me.ComboBox.ValueMember.Substring(Me.ComboBox.ValueMember.LastIndexOf(".") +
1)
> Else
> ValueColName = Me.ComboBox.ValueMember
> End If
>
> If
Me.ComboBox.DataSource.GetType.ToString.EndsWith("dsBonReception") Then
> cm =
CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource,
DataMember), CurrencyManager)
> Else
> cm =
CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource),
CurrencyManager)
> End If
>
> dView = CType(cm.List, DataView)
>
> For i = 0 To dView.Count - 1
> If Not IsDBNull(obj) AndAlso Not
IsDBNull(dView.Item(i).Item(ValueColName)) Then
> If obj = 340 And dView.Item(i).Item(ValueColName) = 340 Then
> Dim t As String
> t = ""
> End If
> End If
> If obj.Equals(dView.Item(i).Item(ValueColName)) Then
> Exit For
> End If
> Next
>
> If i < dView.Count Then
> Return dView.Item(i).Item(DisplayColName)
> End If
>
> Return DBNull.Value
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> Else
> Return MyBase.GetColumnValueAtRow(source, rowNum)
> End If
> End Function
>
> Protected Overrides Sub SetColumnValueAtRow(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal value
As Object)
> If Not Me.ComboBox.DataSource Is Nothing Then
> Try
> Dim s As Object = value
> Dim DataMember As String
> Dim ValueColName As String
> Dim DisplayColName As String
> Dim cm As CurrencyManager
> Dim i As Integer
> Dim dView As DataView
>
> If Me.ComboBox.DisplayMember.IndexOf(".") > -1 Then
> DataMember = Me.ComboBox.DisplayMember.Substring(0,
Me.ComboBox.DisplayMember.LastIndexOf("."))
> DisplayColName =
Me.ComboBox.DisplayMember.Substring(Me.ComboBox.DisplayMember.LastIndexOf(".
") + 1)
> Else
> DisplayColName = Me.ComboBox.DisplayMember
> End If
>
> If Me.ComboBox.ValueMember.IndexOf(".") > -1 Then
> ValueColName =
Me.ComboBox.ValueMember.Substring(Me.ComboBox.ValueMember.LastIndexOf(".") +
1)
> Else
> ValueColName = Me.ComboBox.ValueMember
> End If
>
> If
Me.ComboBox.DataSource.GetType.ToString.EndsWith("dsBonReception") Then
> cm =
CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource,
DataMember), CurrencyManager)
> Else
> cm =
CType(Me.DataGridTableStyle.DataGrid.BindingContext(Me.ComboBox.DataSource),
CurrencyManager)
> End If
>
> dView = CType(cm.List, DataView)
>
> For i = 0 To dView.Count - 1
> If s.Equals(dView.Item(i).Item(ValueColName)) Then
> Exit For
> End If
> Next
>
> If i < dView.Count Then
> If source.Position = rowNum Then
> MyBase.SetColumnValueAtRow(source, rowNum,
dView.Item(i).Item(ValueColName))
> End If
> Else
> If source.Position = rowNum Then
> MyBase.SetColumnValueAtRow(source, rowNum, DBNull.Value)
> End If
> End If
>
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> Else
> MyBase.SetColumnValueAtRow(source, rowNum, value)
> End If
> End Sub
>
> Private Sub ComboBox_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _ComboBox.Leave
> If Not isEditing Then
> ComboBox.Hide()
> Exit Sub
> End If
>
> isEditing = False
>
> Try
> Dim value As Object = ComboBox.SelectedValue
>
> If Not value Is Nothing Then
> SetColumnValueAtRow(_cm, _RowNum, value)
> RaiseEvent CurrentCellDataChanged(MyBase.MappingName, value)
> Else
> EnterNullValue()
> RaiseEvent CurrentCellDataChanged(MyBase.MappingName,
DBNull.Value)
> End If
> Catch
> End Try
>
> Invalidate()
> ComboBox.Hide()
> End Sub
>
> '
> ' ComboBox class removing the tab key
> '
> Public Class NoTabComboBox
> Inherits ComboBox
>
> Private pModified As Boolean
> Private KeyPressed As Boolean
> Private MouseClicked As Boolean
>
> Sub New()
> pModified = False
> KeyPressed = False
> MouseClicked = False
> End Sub
>
> Protected Overrides Sub RefreshItem(ByVal index As Integer)
> MyBase.RefreshItem(index)
> End Sub
>
> Protected Overrides Sub SetItemsCore(ByVal items As
System.Collections.IList)
> MyBase.SetItemsCore(items)
> End Sub
>
> Protected Overrides Function ProcessKeyMessage(ByRef m As
System.Windows.Forms.Message) As Boolean
> If m.Msg = &H101 Then '&H101 = WM_KEYUP
> If m.WParam.ToInt32 = 9 Then '9 = TABKEY
> Return True
> End If
> End If
> Return MyBase.ProcessKeyMessage(m)
> End Function
>
> Public ReadOnly Property Modified() As Boolean
> Get
> Modified = pModified
> End Get
> End Property
>
> Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
> MouseClicked = True
> End Sub
>
> Protected Overrides Sub OnSelectedValueChanged(ByVal e As
System.EventArgs)
> If MouseClicked Or KeyPressed Then
> pModified = True
> MouseClicked = False
> KeyPressed = False
> Else
> pModified = False
> End If
>
> MyBase.OnSelectedValueChanged(e)
> End Sub
>
> Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
> If Char.IsLetterOrDigit(e.KeyChar) Then
> KeyPressed = True
> End If
>
> MyBase.OnKeyPress(e)
> End Sub
> End Class
> End Class
>