This is a migrated thread and some comments may be shown as answers.
Error due dynamically change RadComboBox items
1 Answer 21 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Peter Bogoyavlensky
Top achievements
Rank 1
Peter Bogoyavlensky asked on 18 Nov 2009, 01:32 PM
I try to change RadComboBoxItems collection through casting SelectedIndexChanged event (for localization reasons). And it works fine in version 2009.2.729. But in current version 2009.3.1103 it produced exception ("Object reference not set to an instance of an object") if I change item in combobox. If I press button - all works fine.

What's wrong with that code?

Public Class RadForm1 
    Private m_cmbCurLanguage As Boolean = False 
 
    Private Sub RadForm1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
        AssignCurLanguage(0) 
        m_cmbCurLanguage = True 
    End Sub 
 
    Private Sub AssignCurLanguage(ByVal lng As Integer
        Dim lng1 As String = "", lng2 As String = "", lng3 As String = "" 
 
        Select Case lng 
            Case 0 
                lng1 = "Eng1" : lng2 = "Ger1" : lng3 = "Fra1" 
            Case 1 
                lng1 = "Eng2" : lng2 = "Ger2" : lng3 = "Fra2" 
            Case 2 
                lng1 = "Eng3" : lng2 = "Ger3" : lng3 = "Fra3" 
        End Select 
 
        m_cmbCurLanguage = False 
 
        cmbCurLanguage.Items.Clear() 
        cmbCurLanguage.Items.Add(New Telerik.WinControls.UI.RadComboBoxItem(lng1, 0)) 
        cmbCurLanguage.Items.Add(New Telerik.WinControls.UI.RadComboBoxItem(lng2, 1)) 
        cmbCurLanguage.Items.Add(New Telerik.WinControls.UI.RadComboBoxItem(lng3, 2)) 
 
        cmbCurLanguage.SelectedIndex = lng 
    End Sub 
 
    Private Sub cmbCurLanguage_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles cmbCurLanguage.SelectedIndexChanged 
        If m_cmbCurLanguage Then 
            AssignCurLanguage(cmbCurLanguage.SelectedIndex) 
            m_cmbCurLanguage = True 
        End If 
    End Sub 
 
    Private Sub RadButton1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles RadButton1.Click 
        AssignCurLanguage(1) 
        m_cmbCurLanguage = True 
    End Sub 
End Class 

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 18 Nov 2009, 05:13 PM
Hi Peter Bogoyavlensky,

Thank you for writing.
Your code worked before because the selection events were not working correctly until Q3 2009. You are changing the collection in the SelectedIndexChanged event handler which could potentially cause more SelectedIndexChanged events. Doing this is undefined and you may experience other issues beside this one, for example a StackOverflowException.
You should not clear the collection and re-add the items. In your case simply changing the Text property of the existing RadComboBoxItems should suffice.
Please write again if you need further assistance.
 

Sincerely yours,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Peter Bogoyavlensky
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or