BindingSource_CurrentChanged with RadComboBox value

3 posts, 0 answers
  1. Zachary
    Zachary avatar
    8 posts
    Member since:
    Feb 2008

    Posted 05 May 2008 Link to this post

    I have a form with a combobox which has some values entered during design-time.  I also have a datagridview.  I'm trying to convert this so I am using RadControls combobox and gridview.

    Here is my working code using built in controls:

        Private Sub CustomerBindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingSource.CurrentChanged
            Me.customerID = CType(Me.CustomerBindingSource.Current, DataRowView).Row.Item("CustomerID")
            filldgvCustomerVariousData(Me.customerID, Me.ComboBox1.SelectedItem)
        End Sub

    Here is my attempted code using RadControls:

            Dim item As RadComboBoxItem = TryCast(rcbo_ShowTransactions.SelectedItem, RadComboBoxItem)
            Me.customerID = CType(Me.CustomerBindingSource.Current, DataRowView).Row.Item("CustomerID")
            filldgvCustomerVariousData(Me.customerID, item.Text)

    The above code will work, but only after I get errors saying that the value of selecteditem is Null and if I Step Over and then go select a value in the RadComboBox. 

    This is probably true because the form has not yet completely loaded so I have not yet selected an item.  But I do have some default text in the RadComboBox.  So, maybe SelectedItem isn't the right thing to be using.  Is there something else I can try?

    Thanks!

  2. Zachary
    Zachary avatar
    8 posts
    Member since:
    Feb 2008

    Posted 05 May 2008 Link to this post

    I have made a workaround, but I'm not sure this is the best solution.

    I have changed the code to include an IF...THEN

            Me.customerID = CType(Me.CustomerBindingSource.Current, DataRowView).Row.Item("CustomerID")
            Dim item As RadComboBoxItem = TryCast(rcbo_ShowTransactions.SelectedItem, RadComboBoxItem)
            If item Is Nothing Then
                filldgvCustomerVariousData(Me.customerID, "Contracts")
            Else
                filldgvCustomerVariousData(Me.customerID, item.Text)
            End If


    While this works, I'm curious if it is the best method since it does work fine without the IF...THEN if I use standard controls and not RadControls..

    Thanks for any help.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 07 May 2008 Link to this post

    Hello Zachary,

    I have tested the same scenario and it appears that RadComboBox and the standard MS combobox return different values for the SelectedItem property when the form is initially loaded. This happens because of the specific design of RadComboBox - setting RadComboBox.Text property does not change the value of SelectedItem (SelectedIndex or SelectedValue) property. 

    Nevertheless, your workaround is quite appropriate. Another way could be setting SelectedIndex or SelectedItem property to the desired value on form creation (before firing Form.Load event).
     

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top