By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,426 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

DataGridView and ComboBox columns

P: n/a
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.

Mar 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
VJ
In the Value Changed Event of previous column, you can set the properties as
below

if ( value.Equals("1") )
{
cb1.DataSource = dsTables.Tables["Table1"];
cb1.DisplayMember="Col1";
}
else
{
cb1.DataSource = dsTables.Tables["Table2"];
cb1.DisplayMember="Col2";
}
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
>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.

Mar 12 '07 #2

P: n/a
I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For this
example, I pick item 3 for column two. However, if I start a second row and
select "option two" in the first column and then try and fill the combo box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo box
in column two. Even if you resolve the problem you are having, then you will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"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.
Mar 12 '07 #3

P: n/a
VJ
Phil, you have to clear the DataSet binding, and the ComboxText before
associating a new DataSource. At the minimum, you should say ComboxBox1.Text
= "" and then bind the new datasource. If you have any code in the second
combobox selectedIndex or ValueChanged, beware of them, they might fire when
you clear text.. depending on how your property is organized..

VJ

"Phil" <Ph**@discussions.microsoft.comwrote in message
news:F2**********************************@microsof t.com...
>I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger
problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For
this
example, I pick item 3 for column two. However, if I start a second row
and
select "option two" in the first column and then try and fill the combo
box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo
box
in column two. Even if you resolve the problem you are having, then you
will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"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.

Mar 12 '07 #4

P: n/a
I think this will work for a stand-alone combobox but not for a combobox used
within the atagridview.

I am instead going to add another column and depedning upon the first
selection, either column A or Column B will be active.
"VJ" wrote:
Phil, you have to clear the DataSet binding, and the ComboxText before
associating a new DataSource. At the minimum, you should say ComboxBox1.Text
= "" and then bind the new datasource. If you have any code in the second
combobox selectedIndex or ValueChanged, beware of them, they might fire when
you clear text.. depending on how your property is organized..

VJ

"Phil" <Ph**@discussions.microsoft.comwrote in message
news:F2**********************************@microsof t.com...
I am trying to do a similar sort of thing (but I populate the second combo
box from a list, not a data source) and I have found an even bigger
problem.
If I select "option one" in the first column and then fill the second
column's combo box with options "1, 2, 3, 4", I have no problems. For
this
example, I pick item 3 for column two. However, if I start a second row
and
select "option two" in the first column and then try and fill the combo
box
in column two with "5, 6, 7, 8", then I get a data error because "3", the
selection made in row one, is no longer a valid selection for the combo
box
in column two. Even if you resolve the problem you are having, then you
will
still be restricted by this problem.

Hopefully, someone can help us resolve this as well.

Phil

"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.


Mar 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.