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.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,885 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,708 questions
C#
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.
10,863 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 84,721 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,406 Reputation points
    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 Answers by the question author, which helps users to know the answer solved the author's problem.