Multiple field DisplayMember

5 posts, 0 answers
  1. Nick Jones
    Nick Jones avatar
    18 posts
    Member since:
    Jun 2009

    Posted 24 Mar 2011 Link to this post

    Hi

    Linking a dropdownlist to a datatable seems simple enough:

    cbEName.DataSource = Main.DataSet.Employee
    cbEName.DisplayMember = "FName"
    cbEName.ValueMember = "id"

    But I want to display the persons full name and the display member.  Logically I'd write something like this:

    cbEName.DataSource = Main.DataSet.Employee
    cbEName.DisplayMember = "FName" & " " & "LName"
    cbEName.ValueMember = "id"

    But that obviously doesn't work.  Anyone know how to run through the dropdown list collection and add the surname?
  2. Nick Jones
    Nick Jones avatar
    18 posts
    Member since:
    Jun 2009

    Posted 25 Mar 2011 Link to this post

    In case anyone is interested this is how I solved it.

    For Each record As DataSet.EmployeeRow In Main.DataSet.Employee
                For Each emp As RadListDataItem In cbEName.Items
                    If record.id = emp.Value Then
                        emp.Text = emp.Text.Trim & " " & record.LName
                    End If
                Next
            Next
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Mar 2011 Link to this post

    Hello Nick,

    Thank you for writing and for sharing your solution.

    You can also subscribe to the VisualListItemFormatting event of the RadDropDownList and format the text of the menu items. There is a small drawback as the text in the RadDropDownList will display only the display member not the formatted text of the menu item. The plus however is that you will avoid the two nested foreach loops.

    void radDropDownList1_VisualListItemFormatting(object sender, VisualItemFormattingEventArgs args)
    {
       DataRowView row = args.VisualItem.Data.DataBoundItem as DataRowView;
       args.VisualItem.Text = row["FirstName"] + " " + row["LastName"];        
    }

    I hoper this will be useful. If you need further assistance, I would be glad to provide it.

    Best wishes,
    Ivan Petrov
    the Telerik team
  5. PROGRA
    PROGRA avatar
    7 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2013 Link to this post

    ADD TO PROPERTY ValueMember
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 23 Jul 2013 Link to this post

    Hello Cervantes,

    Thank you for writing.

    Unfortunately, half of a sentence is not enough for me what do you mean, hence I am not able to give you any kind of meaningful answer. Can you please, explain what your question is or what you want to achieve in more details. Any pictures or sketches that illustrate your requirement would also be very useful.

    Looking forward to your reply.

    Regards,
    Ivan Petrov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready