Dataset Column Expressions

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have a data set with a number of added columns having
calculation expressions based on other columns in the same
table and child tables. Some textboxes are bound to these
calculated columns.

When the DataSet loads, the calculated columns are
evaluated correctly.

But when I update other textboxes bound to columns which
contribute to the calculated columns, the calculated
columns do not change.

When should recalculation happen? and how can I force it
to happen.
 
Bob,

I think the recalculation should happen as soon as you move off that row. I haven't tested this but you may want to try it. If this is true then try to call EndCurrentEdit on the
CurrencyManager and see if this forces the calculated columns to re-calculate.

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
Thanks for your reply. This works up to a point. I have a form which
displays a master record, and two DataGrids which display two sets of
detail records. Two textboxes on the main form are bound to added
columns in the main data set. Those columns have expressions which sum
numeric fields on the child records in the grids. The main form also
contains other textboxes bound to "real" currency fields in the master
record.

If I edit one of the grid fields, then shift focus onto the main part of
the form, then call CurrencyManager.Refresh the total fields will not
update, nor will other bound boxes based on other currency fields.

If I do the same edit on the grid, followed by an edit on any of the
master fields, and then call the refresh method, all the bound fields
including the total fields update as would be expected.

It seems as though the Currency Manager ignores the grid edits, so that
when the refresh method is called it considers that there is nothing to
refresh. Editing a master field "jogs" it into action.

Sorry for such a long post. Any ideas?
 
Sorry about delay in replying. This works up to a point.

Imagine a form that displays a master record. It's
controls are bound to a dataset table. Some controls have
summation expressions based on that master table.

The form has a Datagrid bound to a child table. A control
on the "Master" part of the form is bound to a column * in
the master table which has an expression summing a column
of fields in the child table.

When the user is finished editing values in the grid, then
the column * should update to reflect the new total. But
it doesn't. I have tried calling CurrencyManager
[dataset,"master_table"].Refresh
also ...."child_table"].Refresh in the grid's Leave event
but it doesn't work.

If called from a control on the master part of the form
then the update takes place.

Any ideas?

Bob


-----Original Message-----
Bob,

I think the recalculation should happen as soon as you
move off that row. I haven't tested this but you may want
to try it. If this is true then try to call
EndCurrentEdit on the
CurrencyManager and see if this forces the calculated columns to re-calculate.

I hope this helps!


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft
Strategic Technology Protection Program and to order your
FREE Security Tool Kit, please visit
 
Hi Bob,

It looks like the problem is specific to your scenario. Would it be possible to send me a simple project that will reproduce the same behavior so that I look at it? If possible
make to use a sample database like Northwind or Pubs.


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
Hello,


I've produced a sample to show the problem, how do I email
it to you?

Regards
Bob

-----Original Message-----
Hi Bob,

It looks like the problem is specific to your scenario.
Would it be possible to send me a simple project that will
reproduce the same behavior so that I look at it? If
possible
make to use a sample database like Northwind or Pubs.


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft
Strategic Technology Protection Program and to order your
FREE Security Tool Kit, please visit
 
Bob,

We prefer all communication to stay through this newsgroup so please attach it to your reply message.


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
Hi Bob,

Thanks for submitting the sample code. I reproduced the same behavior as you did describe. I think what you are running into is just a timing issue. Please continue
reading.

This is how to verify that it is timing issue:

- Simply add a MessageBox in the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
MessageBox.Show("grdOrder_Details_Leave event"); //Add this line
doRecalc();

- Run the program as you described, click OK on the message box and you will see the value changes.

So to resolve this issue, no need to do anything execpt adding one line of code that will force the Application to simulate a delay before refreshing the CurrencyManager.
This line of code can be added to the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
Application.DoEvents(); //Add this line
doRecalc();

The Application.DoEvents with the currency manager's Refresh method will cause the Total text box to display the correct value upon leaving the datagrid without the need to
have a Refresh button.

I hope this will work for you in the original application. Let me know if you have other questions or concerns.

Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
 
Thanks very much. I will try this out and let you know.

Regards
Bob

Hussein Abuthuraya said:
Hi Bob,

Thanks for submitting the sample code. I reproduced the same behavior as
you did describe. I think what you are running into is just a timing issue.
Please continue
reading.

This is how to verify that it is timing issue:

- Simply add a MessageBox in the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
MessageBox.Show("grdOrder_Details_Leave event"); //Add this line
doRecalc();

- Run the program as you described, click OK on the message box and you will see the value changes.

So to resolve this issue, no need to do anything execpt adding one line of
code that will force the Application to simulate a delay before refreshing
the CurrencyManager.
This line of code can be added to the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
Application.DoEvents(); //Add this line
doRecalc();

The Application.DoEvents with the currency manager's Refresh method will
cause the Total text box to display the correct value upon leaving the
datagrid without the need to
have a Refresh button.

I hope this will work for you in the original application. Let me know if
you have other questions or concerns.
Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
 
Hussein

Thanks very much. Yes that did work in the actual program, and also in
another problematical comms app I'm developing. DoEvents seems to be the
Magic Ingredient!

Best Regards
Bob Morris

Hussein Abuthuraya said:
Hi Bob,

Thanks for submitting the sample code. I reproduced the same behavior as
you did describe. I think what you are running into is just a timing issue.
Please continue
reading.

This is how to verify that it is timing issue:

- Simply add a MessageBox in the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
MessageBox.Show("grdOrder_Details_Leave event"); //Add this line
doRecalc();

- Run the program as you described, click OK on the message box and you will see the value changes.

So to resolve this issue, no need to do anything execpt adding one line of
code that will force the Application to simulate a delay before refreshing
the CurrencyManager.
This line of code can be added to the grdOrder_Details_Leave event as:

this.objOrderDet.Order_Details.AcceptChanges();
Application.DoEvents(); //Add this line
doRecalc();

The Application.DoEvents with the currency manager's Refresh method will
cause the Total text box to display the correct value upon leaving the
datagrid without the need to
have a Refresh button.

I hope this will work for you in the original application. Let me know if
you have other questions or concerns.
Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
 
Back
Top