Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

Modifications to DataGridView aren't reflected in Rows[]

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean Aitken - 19 Jan 2007 15:45 GMT
Good morning,

I'm trying to update a DataSet based on data that has been modified in
a DataGridView. The DataSet isn't binded to the DataGridView because of
a couple conversions. (In this case, a time interval, or TimeSpan, is
stored as number of milliseconds). I haven't found an elegant way to
use the DataSource feature of the DataGridView and allow the
millisecond timespan representation to be displayed as a user-friendly
TimeSpan.  To handle this disconnection, I'm simply creating a
DataTable that contains the data the way I want things to appear in the
DataGridView. This works well.

My problem is when I want to save the changes back to the database.
After the user makes a change to a cell and hits 'enter', the "New" row
below is highlighted (indicating that the change was performed on the
cell / row in question). Programatically, I read in the values from the
DataGridView.Rows[] collection.  The values I find are the original
values from before the changes were made.

Is there some magic property I'm missing or certain way to get the
modified rows of a DataGridView? I have found nothing in the
documentation that sheds any insight. Should I just hold a reference to
a DataTable locally, bind THAT to the DataGridView, then just look at
the table for changes? Why aren't the Rows[] giving me my changes?

Thanks in a advance!
-Sean
Sean Aitken - 19 Jan 2007 16:55 GMT
Found my problem. I had two instances of the DataGridView in the
context I was working. I had a property exposing the one I thought I
was working with. Turns out, it was the wrong one. ooops.

Working as designed! The Value property does in fact give me the new
value.

Cheers!
-Sean

> Good morning,
>
[quoted text clipped - 23 lines]
> Thanks in a advance!
> -Sean
RobinS - 19 Jan 2007 21:52 GMT
Congrats! By the way, you can capture the Format and Parse events
on the cells of the datagrid for that field you want special formatting
on.
These events sit between pulling the data from the data source and
outputting the data into the grid cell. So in one direction, you can
take the number and format it; in the other direction, you can unformat
it and store it.

Robin S.
-----------------------------
> Found my problem. I had two instances of the DataGridView in the
> context I was working. I had a property exposing the one I thought I
[quoted text clipped - 40 lines]
>> Thanks in a advance!
>> -Sean

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.