DataGridView and Combobox columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
Page 62 of this coument has the answer:
http://www.windowsforms.net/Samples/Go To Market/DataGridView/DataGridView FAQ.doc


Manish Bafna said:
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 said:
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.
 
Back
Top