SelectedIndexChanged Event not workking correctly

5 posts, 0 answers
  1. Web
    Web avatar
    88 posts
    Member since:
    Nov 2006

    Posted 02 Aug 2007 Link to this post

    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!!
  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 03 Aug 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 17 Mar 2008 Link to this post

    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.
  5. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 17 Mar 2008 Link to this post

    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.
  6. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 18 Mar 2008 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready