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

Multiple ComboBoxes with same Provider

3 Answers 46 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.
Chase Florell
Top achievements
Rank 1
Chase Florell asked on 17 Mar 2008, 05:16 PM

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) 

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 18 Mar 2008, 04:04 PM
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
0
Chase Florell
Top achievements
Rank 1
answered on 20 Mar 2008, 11:59 PM
Works Great... Way less code.
0
Martin Vasilev
Telerik team
answered on 21 Mar 2008, 06:18 PM
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
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Chase Florell
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Chase Florell
Top achievements
Rank 1
Share this question
or