Solved combobox valuemember question

Posted on 2012-09-13
Last Modified: 2012-09-16
Hi Experts,
I'm struggling with the valuemember within a combo box within a windows application

I've populated my combobox using
        cboControl.DataSource = m
            cboControl.DisplayMember = "name"
            cboControl.ValueMember = "id"

data looks like
id    Name
1     Mark
5     Fred
8     Claire
55   Vikki

etc etc....

which all works fine and it displays the name in the combobox as expected

However what i want to do is set the displaymember from somewhere else in my application however i don't have the "Name" all i have is the "ID"

I understand i can get the valuemember by using "cboControl.SelectedValue.ToString"

So my question is is how would i select say the name "Vikki" when all i have is the "ID" of 55?

thanks in advance
Question by:potnoodle13
    LVL 6

    Accepted Solution

    Just assign the ID to SelectedValue like this:
    cboControl.SelectedValue = 55

    Open in new window

    The combobox will automatically display the corresponding name from your datasource.

    Author Closing Comment


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now