This is a migrated thread and some comments may be shown as answers.

BindingSource_CurrentChanged with RadComboBox value

2 Answers 57 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Zachary
Top achievements
Rank 1
Zachary asked on 05 May 2008, 08:05 PM
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 Answers, 1 is accepted

Sort by
0
Zachary
Top achievements
Rank 1
answered on 06 May 2008, 02:46 AM
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.
0
Georgi
Telerik team
answered on 07 May 2008, 05:26 PM
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
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Zachary
Top achievements
Rank 1
Answers by
Zachary
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or