1

I have a datagridview which has multiple text columns and a single comboboxcolumn. I need to specify a datasource for the iems of the comboboxcolumn and another datasource for the other text columns. I have tried the following sample code but it does not work.

dgv1.DataSource = DataSet1.Tables[0];
string[] managerList = Array.ConvertAll(DataSet2.Select(), row => (string)row[0]);
comboboxcolumn1.DataSource = managerList;

The managerList array has the entries that are to be populated into the combobox but they never show up.

Is that so that I can not have a separate datasource for a comboboxcolumn and its parent datagridview?

Thanks in advance.

1 Answers1

1

I have checked with the following code and it works fine

string[] arr = "This Should Get Displayed".Split(); //managerList in your case           
dataGridView1.DataSource = MyData(false);
(dataGridView1.Columns["Column1"] as DataGridViewComboBoxColumn).DataSource = new BindingSource(arr, null); // Bind to the column of grid

Can you try assigning it as referencing it as a column of your datagridview.

This displays the text split on space in my combobox.

When you are using string array no need to specify Display and Value member for the column

EDIT

If you have a DataTable you can also do it in this fashion

(dataGridView1.Columns["Column1"] as DataGridViewComboBoxColumn).DataSource= datatable;
(dataGridView1.Columns["Column1"] as DataGridViewComboBoxColumn).DisplayMember="columnname";
(dataGridView1.Columns["Column1"] as DataGridViewComboBoxColumn).ValueMember="columnname";
V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • This is still not working. Have you set the datasource of your datagridview to something else? Something that does not provide the data for the comboboxcolumn? – csharpenthusiast11 May 10 '11 at 06:56
  • Yes .. currently the grid datasource has no relation for comboboxcolumn .. Do you have that in your case ? – V4Vendetta May 10 '11 at 06:58
  • I have created a working example wherein the comboboxcolumn gets the values from a subset of the values coming from a stored procedure. But handling 2 datasets seems to be a problem. – csharpenthusiast11 May 10 '11 at 07:02
  • Sorry for that! Whats MyData(false) ? – csharpenthusiast11 May 10 '11 at 07:03
  • In my example MyData is a method which set a `DataTable` as `DataSource` (some hard coded values) – V4Vendetta May 10 '11 at 07:05
  • Thanks for your time dude. Its still not working at my end though. I gues trying all that you have written out patiently should do the trick. I will mark it as the answer when I get it working. +10 for your time. :) – csharpenthusiast11 May 10 '11 at 07:13