Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
Custom combo databinding two values
posted

I'm creating a custom control inherited from the UltraCombo for a standard lookuplist of foreign relationships that I can use in my entire program.  However, I'm having a databinding issue, which maybe a simple fix because I'm new at using databinding in VB.  The list in this Combo will always be filled with an Id (perhaps CustomerId) and some string value (perhaps CustomerName). For this explaination I'll use the a basic relationship of Orders and Customers in which I have an Order form with a bindingsource call OrdersBindingSource and a combo of customers.  The combo list will be filled with CustomerId and CustomerName.  The CustomerName value will be the DisplayMember AND ValueMember of the combo (I know this is unusual). I added a property to this new combo class called "ID" and set my databindings for the combo to: ID = OrdersBindingSource.CustomerId and value = OrdersBindingSource.CustomerName.  Everything is good at this point.  When I run my program the combo displays the customer name (even if the customer name is not in the combo list) and popluates the combo.Id property.  However, when a customer is selected from the combo I need it to update the OrdersBindingSource.CustomerId as well as the OrdersBindingSource.CustomerName, but this is not happening.  It's only changing the OrdersBindingSource.CustomerName.  How do I get the OrdersBindingSource.CustomerId to update when the Combo.Id value is changed?

Here is my basic combo property settings:
Display Member: CustomerName
Value Member: CustomerName

Databindings for combo
ID: OrdersBindingSource.CustomerId
Value: OrdersBindingSource.CustomerName

New Combo Class Code
Public Class UltraFlexCombo
    Inherits Infragistics.Win.UltraWinGrid.UltraCombo

    Private _Id As Long

    Private Sub UltraFlexCombo_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ValueChanged
        Me.Id = Me.ActiveRow.Cells("Id").Value
    End Sub

    <Bindable(True), DefaultValue(0)> _
    Public Property Id() As Long
        Get
            Return _Id
        End Get
        Set(ByVal value As Long)
            If _Id <> value Then
                _Id = value
            End If
        End Set
    End Property
End Class

I think I need to raise the OnPropertychanged Event or NotifyPropChange event in the Set method of the Id property, but I'm not sure how to implement this.

Parents
No Data
Reply
  • 80
    posted

    I think I've got it.

    I had to Implement INotifyPropertyChanged and then Shadows the PropertyChanged Event declaration and then I ended up updating my value in the Validating event.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Public Class UltraFlexCombo
    Inherits Infragistics.Win.UltraWinGrid.UltraCombo
    Implements INotifyPropertyChanged

    Public Shadows Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

    Private _Id As Long

    Private Sub NotifyPropertyChanged(ByVal info As String)
     RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub

    Private Sub UltraFlexCombo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Validating
     Me.Id = Me.ActiveRow.Cells("Id").Value
    End Sub


    <Bindable(True), DefaultValue(0)> _
    Public Property Id() As Long
     Get
      Return _Id
     End Get
     Set(ByVal value As Long)
      If _Id <> value Then
       _Id = value
       NotifyPropertyChanged("Id")
      End If
     End Set
    End Property
    End Class

    I've only done limited testing, but it seems to work so far.

     

     

Children
No Data