Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 806633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:16:27+00:00 2026-05-15T00:16:27+00:00

I have a populate combobox, and I’m so happy with it that I’ve even

  • 0

I have a “populate combobox”, and I’m so happy with it that I’ve even started using more comboboxes. It takes the combobox object by reference with the ID of the “value set” (or whatever you want to call it) from a table and adds the items and their respective values (which differ) and does the job.

I’ve recently had the brilliant idea of using comboboxes in a gridview, and I was happy to notice that it worked JUST LIKE a single combobox, but populating all the comboboxes in the given column at the same time.

ObjComboBox.Items.Add("yadayada");
//works just like
ObjComboBoxColumn.Items.Add("blablabla");

But When I started planning how to populate these comboboxes I’ve noticed: There’s no “Values” property in ComboBoxDataColumn.

ObjComboBox.Values = whateverArray;
//works, but the following doesn't
ObjComboBoxColumn.Values = whateverArray;

Questions:
0 – How do I populate it’s values ? (I suspect it’s just as simple, but uses another name)
1 – If it works just like a combobox, what’s the explanation for not having this attribute ?


—–[EDIT]——

So I’ve checked out Charles’ quote, and I’ve figured I had to change my way of populating these bad boys. Instead of looping through the strings and inserting them one by one in the combobox, I should grab the fields I want to populate in a table, and set one column of the table as the “value”, and other one as the “display”. So I’ve done this:

ObjComboBoxColumn.DataSource = DTConfig; //Double checked, guaranteed to be populated

ObjComboBoxColumn.ValueMember = "Code"; 
ObjComboBoxColumn.DisplayMember = "Description";

But nothing happens, if I use the same object as so:

ObjComboBoxColumn.Items.Add(“StackOverflow”);

It is added.

There is no DataBind() function.

It finds the two columns, and that’s guaranteed (“Code” and “Description”) and if I change their names to nonexistant ones it gives me an exception, so that’s a good sign.


—–[EDIT]——

I have a table in SQL Server that is something like

code  |  text
—————
   1    | foo
   2    | bar

It’s simple, and with other comboboxes (outside of gridviews) i’ve successfully populated looping through the rows and adding the texts:

ObjComboBox.Items.Add(MyDataTable.Rows[I]["MyColumnName"].ToString());

And getting every value, adding it into an array, and setting it like:

ObjComboBox.Values = MyArray;

I’d like to populate my comboboxColumns just as simply as I do with comboboxes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:16:27+00:00Added an answer on May 15, 2026 at 12:16 am

    I don’t mean to sound obnoxious, but do you know there’s documentation for all this stuff?

    From http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx:

    You can populate the column drop-down
    list manually by adding values to the
    Items collection. Alternatively, you
    can bind the drop-down list to its own
    data source by setting the column
    DataSource property. If the values are
    objects in a collection or records in
    a database table, you must also set
    the DisplayMember and ValueMember
    properties. The DisplayMember property
    indicates which object property or
    database column provides the values
    that are displayed in the drop-down
    list. The ValueMember property
    indicates which object property or
    database column is used to set the
    cell Value property.


    EDIT:

    From your edit, it sounds like you might be trying to use non-public properties of the underlying type for DisplayMember and/or ValueMember. Or if your combobox datasource is a DataTable, make sure it has “Code” and “Description” columns.

    Here’s a simple demo. I create a list of Foo’s and assign it as the DataSource of my combobox column. Just create a winforms application and paste this in.

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }                
    
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
    
            // this will be the datasource for the combo box column; you could also bind it to a dataset
            List<Foo> foos = new List<Foo>() {
                new Foo() { FooID = 0, FooName = "No Foo." }, 
                new Foo() { FooID = 1, FooName = "Foo Me Once" },
                new Foo() { FooID = 2, FooName = "Foo Me Twice" },
                new Foo() { FooID = 3, FooName = "Pity The Foo!" }
            };
    
            DataGridView dataGridView1 = new DataGridView();
            dataGridView1.AutoGenerateColumns = false;
    
            // add normal text column
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "MyText";
            column.Name = "Text";
            dataGridView1.Columns.Add(column);
    
            // add the combo box column 
            DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn();
            comboCol.Name = "Foo";
            // bind it to the list of foos to populate it
            comboCol.DataSource = foos;
            // specify which property of the grid's datasource to bind 
            comboCol.DataPropertyName = "MyFoo";
            // specify the property of the combo's datasource to bind 
            comboCol.ValueMember = "FooID";
            // specify the property of the combo's datasource to display
            comboCol.DisplayMember = "FooName";
    
            dataGridView1.Columns.Add(comboCol);
    
            // add some data
            BindingSource bindingSource1 = new BindingSource();
            bindingSource1.Add(new BusinessObject(1, "You say"));
            bindingSource1.Add(new BusinessObject(2, "George says"));
            bindingSource1.Add(new BusinessObject(3, "Mr. T says"));
            bindingSource1.Add(new BusinessObject());
            dataGridView1.DataSource = bindingSource1;
    
            Controls.Add(dataGridView1);
            dataGridView1.Dock = DockStyle.Fill;
        }        
    
        class Foo
        {
            public int FooID { get; set; }
            public string FooName { get; set; }        
        }
    
        class BusinessObject
        {
            public BusinessObject(int foo, string text)
            {
                MyFoo = foo;
                MyText = text;
            }
            public BusinessObject()
            {
                MyFoo = 0;
                MyText = "";
            }            
            public string MyText { get; set; }
            public int MyFoo { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox, that I populate from a web service: public Configure() {
how populate ComboBox and DataGridView using MVP (Model-View-Presenter). Actually i have something like this:
I have a combobox that I populate like this: this.reqTypeInput.Items.Add(new RequestType(Label 1, Value1)); this.reqTypeInput.Items.Add(new
Suppose we have a WPF ComboBox and want to populate it using ObjectDataProvider. <ObjectDataProvider
I have the following code that I'm trying to use to populate a ComboBox,
Hi i need to populate a combobox using the selected value in another combo.
At the moment I have a combobox that is populated from the name fields
I have to populate a QTreeWidget with items (or children of items) that may
I have UIScrollView which i populate with UIImageViews programmatically. After that I change contentSize
I have the following table structure: I'm trying to populate a combobox of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.