Specify comboboxcolumn for bound datatable column
-
I have a datatable as the datasource for a datagridview. One of the columns displays IDs for another datatable (this relationship is specified in the dataset). Is there any way to specify that this column should be a comboboxcolumn, bound to the related table, rather than just a textboxcolumn?
-
I have a datatable as the datasource for a datagridview. One of the columns displays IDs for another datatable (this relationship is specified in the dataset). Is there any way to specify that this column should be a comboboxcolumn, bound to the related table, rather than just a textboxcolumn?
Yes there is. Use the DataGridView designer to modify the properties for the column. Also try using a BindingSource (bound to your DataSet) as the data source for the DataGridView. That way you can bind the DataGridView rows to one table and the ComboBoxColumn drop-down to another table easily through the designer.
- Xint0
-
Yes there is. Use the DataGridView designer to modify the properties for the column. Also try using a BindingSource (bound to your DataSet) as the data source for the DataGridView. That way you can bind the DataGridView rows to one table and the ComboBoxColumn drop-down to another table easily through the designer.
- Xint0
The table is dynamically generated, so not really accessible to the designer. I'm not sure how I'd use the BindingSource alternative. Is there a good tutorial or some such on how I might do this? Thanks. -- modified at 23:57 Thursday 2nd November, 2006 Maybe I should be more specific. I have a table of employees, and a table of shifts available to work. There is a table which links the 2 via foreign keys to represent a many-to-many relationship. For easier editing, I create a custom datatable at runtime, where each column represents one of the shifts, and there is one column for specifying the employee's ID. I would like the employee ID column to be a combobox column with the combobox values taken from the employee table (ValueMember = id, DisplayMember = name). Currently, after creating the custom table, I assign it as the datasource of a datagridview, but the default situation is that the column is simply displayed as a textboxcolumn. Is there a way (outside of the designer), to easily do this (I'm still looking into the bindingsource option)? Any help would be appreciated, this has really got me stumped.
-
The table is dynamically generated, so not really accessible to the designer. I'm not sure how I'd use the BindingSource alternative. Is there a good tutorial or some such on how I might do this? Thanks. -- modified at 23:57 Thursday 2nd November, 2006 Maybe I should be more specific. I have a table of employees, and a table of shifts available to work. There is a table which links the 2 via foreign keys to represent a many-to-many relationship. For easier editing, I create a custom datatable at runtime, where each column represents one of the shifts, and there is one column for specifying the employee's ID. I would like the employee ID column to be a combobox column with the combobox values taken from the employee table (ValueMember = id, DisplayMember = name). Currently, after creating the custom table, I assign it as the datasource of a datagridview, but the default situation is that the column is simply displayed as a textboxcolumn. Is there a way (outside of the designer), to easily do this (I'm still looking into the bindingsource option)? Any help would be appreciated, this has really got me stumped.
I finally figured it out. I create the comboboxcolumn before binding to the datatable, bind the column to the employee table, and set its DataPropertyName to the name of the custom table's employee ID column name, and the column from the datatable gets pushed into it.