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

Populate ComboBox with 2 values

5 Answers 111 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Filleau
Top achievements
Rank 1
Filleau asked on 23 Jul 2008, 03:14 PM
I'm searching a simple way to add 2 value in an combo box.

I work with VB and I need to populate it with "Name" and "Phone"
Only the Name need to be listed in the Combo.

I try 

  Dim item1 As New RadComboBoxItem()
      item1.Text = "Anthony"
      item1.Value = "112"
      RadComboBox1.Items.Add(item1)
      item1.Text = "Marc"
      item1.Value = "134"
      RadComboBox1.Items.Add(item1)


But it don't work (It display Marc twice)

My first idea was :
 RadComboBox1.Items.Add("Anthony","112)
 RadComboBox1.Items.Add("Marc","134)


But I can't do that

Who can help me ?

Second thing, how then to sort the combo on Name ?

Thanks

5 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 23 Jul 2008, 03:45 PM
Filleau,

I don't know what the VB equivalent is, but in C# you'd have to say...

RadComboBoxItem itm = new RadComboBoxItem() 
itm.Text = "Anthony"
itm.Value = "112" 
RadComboBox1.Items.Add(itm); 
itm = new RadComboBoxItem() 
itm.Text = "Marc"
itm.Value = "134" 
RadComboBox1.Items.Add(itm); 
 
Hope this helps.

--
Stuart


0
Paul
Telerik team
answered on 23 Jul 2008, 03:47 PM
Hi Filleau,

Please find below your modified code snippet that works as expected.

Imports Telerik.Web.UI  
 
Partial Class Default2  
    Inherits System.Web.UI.Page  
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not Page.IsPostBack Then 
            RadComboBox1.Sort = RadComboBoxSort.Ascending  
            BindCombo()  
            RadComboBox1.SortItems()  
        End If 
 
    End Sub 
 
    Private Sub BindCombo()  
        Dim item1 As New RadComboBoxItem()  
        item1.Text = "Anthony" 
        item1.Value = "112" 
        RadComboBox1.Items.Add(item1)  
 
        Dim item2 As New RadComboBoxItem()  
        item2.Text = "Marc" 
        item2.Value = "134" 
        RadComboBox1.Items.Add(item2)  
    End Sub 
End Class 
 

In addition, you can take a look at our new Sorting example.

All the best,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Filleau
Top achievements
Rank 1
answered on 24 Jul 2008, 04:24 AM
Yeah ! This is what I want do do.

Except I have to do it in a loop so I can't do it like this.

Private Sub BindCombo()
    Dim DirEntry As DirectoryEntry
    For Each result As SearchResult In searcher.FindAll
           Dim Item1 as New RadComboBoxItem()
           DirEntry = result.GetDirectoryEntry
           item1.text = DirEntry.Properties("givenName").Value)
           item1.value = DirEntry.Properties("TelephoneNumber").Value)
    Next
End Sub

What is the best way ? :
1/ Have a Dim Item1 as New RadComboBoxItem() in my loop ?
2/ Declare a array. something like Dim  item(4) as RadComboBoxItem ?

Thanks
0
Filleau
Top achievements
Rank 1
answered on 24 Jul 2008, 07:12 AM
This way seem to work well, but I'm surprise to declare the same var many time.

Private Sub BindCombo()
    Dim DirEntry As DirectoryEntry
    For Each result As SearchResult In searcher.FindAll
           Dim Item1 as New RadComboBoxItem()
           DirEntry = result.GetDirectoryEntry
           item1.text = DirEntry.Properties("givenName").Value)
           item1.value = DirEntry.Properties("TelephoneNumber").Value)
    Next
End Sub

But this code don't work

RadComboBox1.Sort = RadComboBoxSort.Ascending  
            BindCombo()  
            RadComboBox1.SortItems()  

Sort is not a member of 'Telerik.Web.UI.RadComboBox'
0
Accepted
Rosi
Telerik team
answered on 24 Jul 2008, 01:51 PM
Hi Filleau,

This problem is related to the version of the Telerik.Web.UI that you use.

The sorting functionality is implemented in "Futures" Q2 2008 version - 2008.2.708 which you can download from your account and it is included in our official Q2 release which will be ready for download by the end of the week.

Greetings,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Filleau
Top achievements
Rank 1
Answers by
Stuart Hemming
Top achievements
Rank 2
Paul
Telerik team
Filleau
Top achievements
Rank 1
Rosi
Telerik team
Share this question
or