DataBinding

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Hello - I know that you can bind a control to a table and set the
DisplayMember and ValueMember for a particular table. No problem.

My question is if there is a way to relate this to another control. Say
for instance I have a control which allows a user to select "Color" with is
"bound" to a DataTable called "Colors". Then I have another control which
list body styles. Not all body styles are available in all colors. When
the user selects a new color in one control, I only want to display the
body styles which relate to that color.

I know that I can do this with a "DataView" and when the SelectedIndex
changes on the Colors control, I would then set the dataview on the Body
Style Control to the appropriate color.

But is there a better way other then this?
 
It depends on your table structure, but f you use a DataRelation between the
table, you can do it with a BindingContext/BindingManagerBase. Say Color
Blue is chosen and Sedan, Coupe and Economeny are all avaialable. If the
tables are relates and you have a control that supports complex binding, a
grid for example, all three choices will show up in the grid.
 
If I created a view and set the DataView.RowFilter property to the
"SelectedValue" of the "Color" control, wouldn't that work? When a new
color is selected, that would change the "SelectedValue" property of the
Color control, which in turn should modify the the Row Filter... or would I
still have to reset this value manually because it will not be reset
automatically???
 
Yes, you can use the first method, I thought you were looking for a
different approach, but filtering like that will work. You may want to put
something in there that you know will be a dud, like a negative 1 for a
value when all body types are represented by positive numbers when you
initialize the form so you don't get any data in there, but that's a UI
thing an not really that important in this context.

Jim, if you haven't played with the Binding Object's I'd encourage you to
just check them out because you may run into much more complex situations
which can cause you to write a whole lot of extra code.

Good Luck
 
Back
Top