Event for Field Change

G

Guest

I am a Delphi programmer who is excited about converting to .Net (however
still novice in .Net), and I need your help to understand some data
manupulation concepts.
I am using
I have a typed DataGrid bound to an access database, which has a table with
2 datetime fields: Date1 and Date2.
I added an unbound column to the grid called ELAPSED, which will diplay the
difference in days between the 2 dates. So the grid looks like this:
DATE1 DATE2 DIFF
------------------------------------------
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days

I wrote a method to calculate the difference in days (using TimaSpan), and I
want to run this method for each row, as it's been "filled" from the
database. Additionally, I want this method to be run as I change DATE1 or
DATE2 in the grid, so that the it reflects the correct difference in days.
Please help me to achieve this, explaining in what event(s) I should place
the call to my method.

PS: In Delphi I would put it in the TField's OnChange event...

Thank you very much!!!!!
- Gus
 
G

Guest

I am a Delphi programmer who is excited about converting to .Net (however
still novice in .Net), and I need your help to understand some data
manipulation concepts.
I am using VS2005 and C#.
I have a typed DataGrid bound to an access database, which has a table with
2 datetime fields: Date1 and Date2.
I added an unbound column to the grid called ELAPSED, which will diplay the
difference in days between the 2 dates. So the grid looks like this:
DATE1 DATE2 ELAPSED
------------------------------------------
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days
__/__/____ __/__/____ 999 days

I wrote a method to calculate the difference in days (using TimeSpan), and I
want to run this method for each row, as it's been "filled" from the
database. Additionally, I want this method to be run as I change DATE1 or
DATE2 in the grid, so that the it reflects the correct difference in days.
Please help me to achieve this, explaining in what event(s) I should place
the call to my method.

PS: In Delphi I would put it in the TField's OnChange event...

Thank you very much!!!!!
- Gus
 
S

Sahil Malik [MVP]

Guz,

Did you try looking into a new column added based on an expression? That
seems to be the easier way out if you can find an expression taht will
calculate such a column for you.

Lucky for you, you are using .NET 2.0. There are a gazillion other ways to
acheive this. One easy way is to use the RowChanging event, another way is
to use a business object that aggregates your datatable and exposes a
calculated property and then use binding source, yet another way is to
extend the datatable by inheriting and partial classing it. I'm sure there
are many other ways.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top