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

Better written question by GusUzeda

GusUzeda
Tue Sep 27 14:49:04 CDT 2005

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


Re: Better written question by Sahil

Sahil
Wed Oct 05 23:30:24 CDT 2005

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.


--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------



"Gus Uzeda" <GusUzeda@discussions.microsoft.com> wrote in message
news:55905A93-B204-4B33-8BA0-5CE3EF4E664E@microsoft.com...
>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
>