Two forms, two controls, one dataset, one currency

  • Thread starter Thread starter Waxabi X
  • Start date Start date
W

Waxabi X

An application contains two forms FormA and FormB

Form A contains a DataGrid bound to the DataSet ORDERS
Form B contains a ListBox bound to the DataSet ORDERS

How can I get
the selection in FormA.DataGrid to reposition both
1) the DataSet ORDERS
2) and change the ListItem index in FormB.ListBox

--AND at the same time--

get the selection in FormB.ListBox to reposition both
1) the DataSet ORDERS
2) and change the ListItem index in FormA.DataGrid

Keeping everything in synch

Possible?
 
Use the same BindingContext for both controls, in addition to using the same
object as the datasource.

For eg.
BindingContext bctxt = FormA.BindingContext;
DataGrid.BindingContext = bctxt;
ListBox.BindingContext = bctxt;

How you communicate the binding ctxt between the forms depend on your
application.

Let me know if you need more help.
 
That is exactly what my approach was. See the code below. Navigation
in Form A's DataGrid will cause Form B's SelectedValue to change but
Form B's SelectedValue does not cause Form A's DataGrid row index to
change

note DB.DS is static
dgOrders is DataGrid
lbOrders is ListBox

FORM A
dgOrders.DataSource = DB.DS.Tables["Orders"].DefaultView;
dgOrders.SetDataBinding(DB.DS,"Orders");


FORM B
lbOrders.DisplayMember = "DESCR";
lbOrders.ValueMember = "Orders_ID";
lbOrders.DataSource = DB.DS.Tables["Orders"].DefaultView;
lbOrders.DataBindings.Add("SelectedValue", DB.DS.Tables["Orders"],
"Orders_ID");

dgOrders.DataSource = DB.DS.Tables["Orders"];
//dgOrders.SetDataBinding(DB.DS,"Orders");
 
Looks like the problems I was having were due to using the -table's-
binding context in some references and using the -DefaultView's-
context in others.

They both work but you have to consistently stick with one or the
other. It is probably best to always bind to the view because then any
controls bound to custom views derived from the table via the
DataViewManager all stay in harmony.

Thanks for the help
 
Back
Top