Home All Groups Group Topic Archive Search About

DataGridView and Combobox columns

Author
14 Mar 2007 1:03 AM
Chris
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.

Author
14 Mar 2007 6:41 AM
Manish Bafna
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.



Show quoteHide quote
"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.
>
>
Are all your drivers up to date? click for free checkup

Author
17 Mar 2007 6:30 PM
Chris
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.
> >
> >

Bookmark and Share