Populate ComboBox with 2 values

6 posts, 1 answers
  1. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 23 Jul 2008 Link to this post

    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
  2. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 23 Jul 2008 Link to this post

    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


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 23 Jul 2008 Link to this post

    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.
  5. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 23 Jul 2008 Link to this post

    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
  6. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 24 Jul 2008 Link to this post

    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'
  7. Answer
    Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 24 Jul 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017