Nikita

Nikita

  • NA
  • 1
  • 0

DataGridView from 2 tables; One combobox column

May 22 2006 6:56 AM
 

Hi,

I'm having a situation like this.

I am using a datagridview which fills up Item details from a table, say Items.

I am also adding a Datagridcomboboxcolumn to this datagrid whose datasource is table 'Category' from where it should show various category names in combo box for user to select one.

I can see the datagridview being filled up with data from Items table.I can also see the combo box column being generated for each row.However, the combobox doesnot work and show any values from its datasource.

How can I show rows from one table and combo box in each row from other table in a datagridviw ?

here is the pseudocode :

DataTable dt = objItems.GetItems(); // gives Item details in a table.

DataTable dtCat = objCat.GetCategory(); // returns category details in form of a table.

dgItems.DataSource = dt; // dgItems is a datagridview created with the help of toolbox on a winform.

DataGridViewComboBoxColumn comboColumn = new DataGridViewComboBoxColumn();

comboColumn.DataPropertyName = "CategoryDesc";

comboColumn.HeaderText = "Select Category";

comboColumn.MaxDropDownItems = 5;

comboColumn.DataSource = dtCat;

comboColumn.ValueMember = "CategoryId";

comboColumn.DisplayMember = "CategoryDesc";

dgItems.Columns.Insert(dt.Coulmns.Count + 1, comboColumn);

 

Thanks in advance.

Nikita


Answers (1)