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

SelectedIndexChanged Event not workking correctly

4 Answers 103 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.
Web
Top achievements
Rank 1
Web asked on 02 Aug 2007, 05:08 PM
Hello,

i have a very weird issue. Everytime when i select an item from the Combobox the SelectedText value only changes at the second time when the SelectedIndexChanged event is fired. So i have to select the itme twice until i get the Value i want to have. Urgent Problem!!

4 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 03 Aug 2007, 10:59 AM
Hello Kerstin,

The SelectedText property returns the string that represents the currently selected text in the text box part of the combobox. To get always the proper text value of the currently selected item you should use instead:

((RadComboBoxItem)SelectedItem).Text.

If you need further assistance, please write us back and give us some more information about your case.

Sincerely yours,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chase Florell
Top achievements
Rank 1
answered on 17 Mar 2008, 06:25 AM
I am having this same issue with the most current version of WinForms.

My code looks like this

    Private Sub RadComboBox1_SelectedValueChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadComboBox1.SelectedIndexChanged  
 
 
        If RadComboBox1.SelectedIndex = 0 Then 
            Dim hp As New HouseholdsProvider()  
            Dim ds As DataSet = hp.GetHouseholdsAsDataSet()  
            RadComboBox2.DisplayMember = "Name" 
            RadComboBox2.ValueMember = "ID" 
            RadComboBox2.DataSource = ds.Tables(0)  
 
 
        ElseIf RadComboBox1.SelectedIndex = 1 Then 
            Dim op As New OrganizationsProvider()  
            Dim ds As DataSet = op.GetHouseholdsAsDataSet  
            RadComboBox2.DisplayMember = "Organization" 
            RadComboBox2.ValueMember = "ID" 
            RadComboBox2.DataSource = ds.Tables(0)  
 
 
        End If 
 
 
 
    End Sub 

But the problem is that I need to change the data in RCB1 twice before RCB2 binds to the new Provider.
0
Chase Florell
Top achievements
Rank 1
answered on 17 Mar 2008, 07:27 AM
Well I think I got it... can anyone confirm that this is the "Right" way to do it?

        If RadComboBox1.SelectedIndex = 0 Then 
            RadComboBox2.DataSource = Nothing 
            Dim hp As New HouseholdsProvider()  
            Dim ds As DataSet = hp.GetHouseholdsAsDataSet()  
            RadComboBox2.DisplayMember = "Name" 
            RadComboBox2.ValueMember = "ID" 
            RadComboBox2.DataSource = ds.Tables(0)  
 
 
        ElseIf RadComboBox1.SelectedIndex = 1 Then 
            RadComboBox2.DataSource = Nothing 
            Dim op As New OrganizationsProvider()  
            Dim ds As DataSet = op.GetHouseholdsAsDataSet  
            RadComboBox2.DisplayMember = "Organization" 
            RadComboBox2.ValueMember = "ID" 
            RadComboBox2.DataSource = ds.Tables(0)  
 
 
        End If 

Notice how I cleared the datasource before binding to a new one.
0
Georgi
Telerik team
answered on 18 Mar 2008, 12:15 PM
Hi Chase Florell,

I am not quite sure that your issue is the same as with the previous one related to SelectedText. Otherwise, your last approach seems to be ok.

The previous would probably not work because you assign a new value to the DisplayMember property before changing the datasource while the combobox is still bound to the old one. Furthermore, it not needed to set ValueMember twice with the same value.

If you have any other questions, I will be glad to help you.

Kind regards,
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
Web
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Chase Florell
Top achievements
Rank 1
Share this question
or