How to Display multiple columns in WinForms combobox?

Kerry Ou 226 Reputation points
2023-03-22T05:43:11.3733333+00:00

tempsnip

This picture is Access 2010.Data come from SQL. I tried to move to Winform. I know how to bind data sources.

Can WinForms combobox do the same? Show 3 columns and titles, When a row is selected, return only Plan_no.

I am new, maybe I need more detailed examples or code. Thank you so much.

Developer technologies | Windows Forms
SQL Server | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,496 Reputation points
    2023-03-22T07:46:50.19+00:00
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,591 Reputation points Volunteer Moderator
    2023-03-22T10:15:23.53+00:00

    See the following article with code..

    dual

    Mock-up example

    private void Form1_Load(object sender, EventArgs e)
    {
        DataTable dataTable = new DataTable("Employees");
    
        dataTable.Columns.Add("EmployeeID", typeof(int));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Columns.Add("Designation", typeof(string));
    
        dataTable.Rows.Add(1, "Natalia", "Developer");
        dataTable.Rows.Add(2, "Jonathan", "Developer");
        dataTable.Rows.Add(3, "Jake", "Developer");
        dataTable.Rows.Add(4, "Abraham", "Developer");
        dataTable.Rows.Add(5, "Mary", "Team Lead");
        dataTable.Rows.Add(6, "Calvin", "Project Manager");
        dataTable.Rows.Add(7, "Sarah", "Team Lead");
        dataTable.Rows.Add(8, "Monica", "Developer");
        dataTable.Rows.Add(9, "Donna", "Developer");
    
        multiColumnComboBox1.DataSource = dataTable;
        multiColumnComboBox1.DisplayMember = "Name";
        multiColumnComboBox1.ValueMember = "EmployeeID";
    }
    
    private void CurrentButton_Click(object sender, EventArgs e)
    {
        int id = ((DataRowView)multiColumnComboBox1.SelectedItem).Row.Field<int>("EmployeeID");
    }
    
    2 people found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.