1

I am using DataSource Property to Bind the data into ComboBox using C# in the following manner:

          ComboBox1.DataSource=dt;//dt is the datatable which is having the values
          ComboBox1.DisplayMember="column1";
          ComboBox1.ValueMember="column2";

The Problem is that i having all the values in the DataSource of the ComboBox1 i.e.totally five values,But the ComboBox1 count is 1 ,Dont know Why?Can anyone help me,Thanks in advance....................

2
  • You see five items in the ComboBox, but .Count is returning 1, or your DataSource is expected to have 5 items, but only 1 appears in the ComboBox? Commented Mar 31, 2010 at 11:28
  • My DataSource is expected to have 5 items, but only 1 appears in the ComboBox....................... Commented Apr 1, 2010 at 9:23

1 Answer 1

2

There's gotta be more to your problem than just those 3 lines of code. I can reproduce the scenario just fine and it's working. Here's a working code sample:

public class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        var dt = new DataTable();
        dt.Columns.Add("Column1", typeof(string));
        dt.Columns.Add("Column2", typeof(int));

        for (int i = 1; i <= 5; i++)
        {
            dt.Rows.Add("Value " + i.ToString(), i);
        }

        comboBox1.DataSource = dt;
        comboBox1.DisplayMember = "Column1";
        comboBox1.ValueMember = "Column2";
    }
}

It produces the following form:
Form screenshot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.