Multiple ComboBoxes with same Provider

4 posts, 0 answers
  1. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 17 Mar 2008 Link to this post

    How would I bind multiple ComboBoxes to the same provider while still allowing for each ComboBox to be changed independantly?

            Dim cp As New npoCategoriesProvider  
            Dim cds As DataSet = cp.GetCategoriesAsDataSet  
     
            RadComboBox3.DisplayMember = "AccountName" 
            RadComboBox3.ValueMember = "AccountNumber" 
            RadComboBox3.DataSource = cds.Tables(0)  
            RadComboBox4.DisplayMember = "AccountName" 
            RadComboBox4.ValueMember = "AccountNumber" 
            RadComboBox4.DataSource = cds.Tables(0)  
            RadComboBox5.DisplayMember = "AccountName" 
            RadComboBox5.ValueMember = "AccountNumber" 
            RadComboBox5.DataSource = cds.Tables(0)  
            RadComboBox6.DisplayMember = "AccountName" 
            RadComboBox6.ValueMember = "AccountNumber" 
            RadComboBox6.DataSource = cds.Tables(0)  
            RadComboBox7.DisplayMember = "AccountName" 
            RadComboBox7.ValueMember = "AccountNumber" 
            RadComboBox7.DataSource = cds.Tables(0)  
            RadComboBox8.DisplayMember = "AccountName" 
            RadComboBox8.ValueMember = "AccountNumber" 
            RadComboBox8.DataSource = cds.Tables(0) 
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 18 Mar 2008 Link to this post

    Hello Chase Florell,

    Thank you for writing.

    In order to allow changing the value independently for several instances of RadComboBox that use data from the same source, it's easier to manually fill their items, instead of binding them.

    To do this, you could use the function provided below on all instances of RadComboBox:

    Private Sub FillRadComboBox(ByVal radComboBox As RadComboBox, ByVal dataTable As DataTable)  
        Dim i As Integer = 0  
        While i < dataTable.Rows.Count  
            Dim item As New RadComboBoxItem(dataTable.Rows(i)("AccountName").ToString(), dataTable.Rows(i)("AccountNumber"))  
            radComboBox.Items.Add(item)  
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)  
        End While 
        radComboBox.SelectedIndex = 0  
    End Sub 

    I hope this was helpful. Do not hesitate to contact me if you have other questions.

    Regards,
    Martin Vasilev
    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 20 Mar 2008 Link to this post

    Works Great... Way less code.
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 21 Mar 2008 Link to this post

    Hi Chase,

    Thank you for getting back to us.

    You could also create a different DataTable for each RadComboBox, but using the function from my previous post is a much better solution because it won't take memory for all of the DataTables containing the same data.   

    Do not hesitate to contact me again if you need additional assistance. 
     

    Kind regards,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top