|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView and Combobox columnsI am trying to populate a DataGridView Combobox column with a different data
binding source (dataset) depending upon a selection made in a previous column. I can handle the previous column but how do I assign the following properties dynamically in code? DataPropertyName DataSource DisplayMember I do see how to set these at design time but that won't do because I need different data in the combobox per each row depending upon the previous selection made. I hope I explained the problem well enough. Hi,
try this code : DataGridViewComboBoxCell dgvComBox = GetComboBox(); private void DataGridViewComboBoxCell GetComboBox() { DataGridViewComboBoxCell dgvComboBoxCell = new DataGridViewComboBoxCell (); dgvComboBoxCell .ToolTipText = "Some Text "; dgvComboBoxCell.DataSource = "Your Datasource"; dgvComboBoxCell.DisplayMember = "DisplayColumnName"; dgvComboBoxCell ="ValueColumnName" return dgvComboBoxCell ; } Thereafter you can assign this to datagridview cell in following manner: dgvDataGridName.Rows[somecount].Cells[somecount] = dgvComBox ; please let me know if this has worked. -- Show quoteHide quoteIf my answer helped you,then please do press Yes below. Thanks and Regards. Manish Bafna. MCP and MCTS. "Chris" wrote: > I am trying to populate a DataGridView Combobox column with a different data > binding source (dataset) depending upon a selection made in a previous > column. I can handle the previous column but how do I assign the following > properties dynamically in code? > > DataPropertyName > DataSource > DisplayMember > > I do see how to set these at design time but that won't do because I need > different data in the combobox per each row depending upon the previous > selection made. > I hope I explained the problem well enough. > > Page 62 of this coument has the answer:
http://www.windowsforms.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc
Show quoteHide quote "Manish Bafna" wrote: > Hi, > try this code : > > DataGridViewComboBoxCell dgvComBox = GetComboBox(); > > private void DataGridViewComboBoxCell GetComboBox() > { > DataGridViewComboBoxCell dgvComboBoxCell = new DataGridViewComboBoxCell > (); > dgvComboBoxCell .ToolTipText = "Some Text "; > dgvComboBoxCell.DataSource = "Your Datasource"; > dgvComboBoxCell.DisplayMember = "DisplayColumnName"; > dgvComboBoxCell ="ValueColumnName" > return dgvComboBoxCell ; > } > > Thereafter you can assign this to datagridview cell in following manner: > dgvDataGridName.Rows[somecount].Cells[somecount] = dgvComBox ; > > please let me know if this has worked. > > -- > If my answer helped you,then please do press Yes below. > Thanks and Regards. > Manish Bafna. > MCP and MCTS. > > > > "Chris" wrote: > > > I am trying to populate a DataGridView Combobox column with a different data > > binding source (dataset) depending upon a selection made in a previous > > column. I can handle the previous column but how do I assign the following > > properties dynamically in code? > > > > DataPropertyName > > DataSource > > DisplayMember > > > > I do see how to set these at design time but that won't do because I need > > different data in the combobox per each row depending upon the previous > > selection made. > > I hope I explained the problem well enough. > > > >
Other interesting topics
Password protect .mdb file
Urgent Memory Leak Problem Using Type Dataset. Please help! :-( Deployment + Vista Eliminating CRUD procedures Writing xml file from dataset different than the original Import text file with DATE column into MS Access Database with VB.NET or C# How can I use connected mode instead of disconnected? A search module in c# Is it possible to fill a DataSet.DataTable with values from more than one database table? I need an approach to storing/editing data amongs forms |
|||||||||||||||||||||||