OutOfRange bug when in fact it's in range

4 posts, 1 answers
  1. Ioannis
    Ioannis avatar
    35 posts
    Member since:
    Dec 2018

    Posted 24 Jan Link to this post

    Hello,

    So I've come across this weird (possible) bug whereupon if you bing a datatable as datasource in a multicolumn combobox and then try to change the SelectedIndex before the combobox has been drawn to the UI, you get an Index out of range exception even though the index is perfectly fine.

    If you wait for it to be drawn, then it works fine.

     

    I've created a reproducible example where I have a form with a PageView control; there's an "Employee" class whose "NewPage(AvoidBug As Boolean)" function returns a PageViewPage which has a MultiColumn cb inside with a datatable as its DataSource.

    The 1st button on the main form will add the PageViewPage control that the NewPage(False) function returned to the PageView and the mccb.SelectedIndex will be changed inside the NewPage() function (so before it's drawn to the UI)

    The 2nd button will do the same, only calling the NewPage(True) will result in a Public Variable inside the Class being set to the Index we want the mccb.SelectedIndex to be changed to, but the mccb.SelectedIndex will NOT change. After the control is added on the main form, the mccb.SelectedIndex now changes, and no exception is produced.

     

    *So does that mean the the DataSource indexing on a mbcb occurs only after the control is drawn/visible to the user?

    *Another thing I noticed, even when the second button is pushed, the bug avoidance only works once. If you push it again (to add a second PageViewPage) then exception occurs again

    *However, if you delete the first PageViewPage before pushing the second button a second time, essentially adding a first PageViewPage again, then the exception doesn't occur

     

    Things will become much clearer by using the reproducible code: https://www.dropbox.com/s/4ccjr37n60mavt4/TelerikWinFormsApp1%20%282%29.rar?dl=1

     

    Best regards,

    Ioannis Mamalikidis

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3321 posts

    Posted 24 Jan Link to this post

    Hello, Ioannis,      

    The provided sample project is greatly appreciated. It was very helpful for better understanding of the precise case. 

    When you add the RadMultiColumnComboBox at run time, note that it is important to initialize its BindingContext before data binding. Otherwise, you will notice that the RadMultiColumnComboBox.EditorControl.Rows.Count will return 0. I made the following modification of the code and it works as expected now.

    Public Function NewPage(AvoidBug As Boolean) As RadPageViewPage
        'Initialisation
        dtSite = CreateDataSource()
     
        mcbViewEmployeeSite.BindingContext = New BindingContext()
        mcbViewEmployeeSite.DataSource = Nothing
        mcbViewEmployeeSite.Columns.Clear()
        mcbViewEmployeeSite.DataSource = dtSite
        mcbViewEmployeeSite.DisplayMember = "Site_Number"
        mcbViewEmployeeSite.ValueMember = "ID"
     
        Dim compositeFilter As New CompositeFilterDescriptor()
        Dim Site_Number As New FilterDescriptor("Site_Number", FilterOperator.Contains, "")
        Dim Site_Name As New FilterDescriptor("Site_Name", FilterOperator.Contains, "")
        compositeFilter.FilterDescriptors.Add(Site_Number)
        compositeFilter.FilterDescriptors.Add(Site_Name)
        compositeFilter.LogicalOperator = FilterLogicalOperator.[Or]
        mcbViewEmployeeSite.EditorControl.FilterDescriptors.Add(compositeFilter)
     
     
        'Filling in the values
        Dim ValueWeAreLookingFor As Integer = 400
        Dim SiteIndex As Integer = -1
        For i As Integer = 0 To dtSite.Rows.Count - 1
            If CInt(dtSite.Rows(i).Item("Site_Number")) = ValueWeAreLookingFor Then
                SiteIndex = i
                Exit For
            End If
        Next i
        If Not AvoidBug Then
            'The mcb doesn't seem to index the DataSource before it becomes visible to the UI
            mcbViewEmployeeSite.SelectedIndex = SiteIndex 'Here's the exception!
        Else
            EmployeeSiteBugFix = SiteIndex 'If we don't change the SelextedIndex immediately and instead we put the value on a public string
            'and we change it after the function is executed (and the PageView is now visible on the user), it works.
            'So I'm guessing the indexing of the DataSource is done only after the control is visible/drawn
     
            'But even this fix only works once per run for some reason. Pushing the button twice will produce the same exception
     
            'Last thing I've noticed. If before re-pushing the second button, you close the previous page, then the bug doesn't occur
        End If
     
        pvpViewEmployeeResult.Text = String.Format("#{0}", dtSite.Rows(SiteIndex).Item("Site_Name"))
     
        Return pvpViewEmployeeResult
    End Function

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Ioannis
    Ioannis avatar
    35 posts
    Member since:
    Dec 2018

    Posted 24 Jan in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Works like charm!

    Thank you very much. I marked the thread as answered :)

     

    P.S. If you think that this report is a worthy of it, please update my points; If not, that's okay :)

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3321 posts

    Posted 28 Jan Link to this post

    Hello, Ioannis,      

    I am glad that the problem you were facing is now resolved. Please note that this is not an issue with RadMultiColumnComboBox but a specificity when adding and binding controls at run time. 

    You can refer to the following link which gives some additional information how to earn Telerik points: https://www.telerik.com/community/telerik-points 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top