473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

detecting changes in a datagridview

cj
As your probably aware the datagridview doesn't update it's source
datatable with changes to a cell until you move off that cell. Suppose
somone makes a change in a cell of my datagridview then clicks to go
elsewhere in the program--how can I be assured that change is
transmitted back to the source datatable?
Dec 5 '07 #1
7 6277
On Wed, 05 Dec 2007 16:12:03 -0500, cj <cj@nospam.nospamwrote:
>As your probably aware the datagridview doesn't update it's source
datatable with changes to a cell until you move off that cell. Suppose
somone makes a change in a cell of my datagridview then clicks to go
elsewhere in the program--how can I be assured that change is
transmitted back to the source datatable?
One possibility is to force the changes to be made immediately,
although that won't work usefully if you have validation on the cell.

There is a lot of info about DataGridView here:
<http://www.windowsclient.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc>

Section 3.2 describes the process for a checkbox column, and there is
a code snippet here
<http://207.46.236.188/MSDN/ShowPost.aspx?PostID=2105950&SiteID=1>

Googling for CurrentCellDirtyStateChanged has a number of hits, many
of which are not working at the moment but they may work later.

There is also some information here:
<http://www.msdner.com/dev-archive/106/2-7-1062147.shtm>
Dec 5 '07 #2
cj,

Call the EndEdit on the datasource.

Cor
As your probably aware the datagridview doesn't update it's source
datatable with changes to a cell until you move off that cell. Suppose
somone makes a change in a cell of my datagridview then clicks to go
elsewhere in the program--how can I be assured that change is
transmitted back to the source datatable?
Dec 6 '07 #3
Hi Chris,

When we select and type in the current cell in a DataGridView, the editing
control attached to the current cell is shown and the current cell is in
edit mode. If you click on another form in the application, only one event
is fired, i.e. the current editing control's LostFocus event.

So we could subscribe this event to get notified when the user clicks to go
elsewhere in the application so as to apply the changes in the current cell
back to the underlying data source.

The following is a sample to do this:

Private Sub DataGridView1_CellValidated(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellValidated
If (Me.DataGridView1.EditingControl IsNot Nothing) Then
RemoveHandler DataGridView1.EditingControl.LostFocus, AddressOf
Control_LostFocus
End If
End Sub

Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs)
Handles DataGridView1.EditingControlShowing
AddHandler e.Control.LostFocus, AddressOf Control_LostFocus
End Sub

Sub Control_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
If (Me.DataGridView1.IsCurrentCellInEditMode) Then
RemoveHandler Me.DataGridView1.EditingControl.LostFocus,
AddressOf Control_LostFocus
Me.DataGridView1.EndEdit()
End If
End Sub

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

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

Dec 6 '07 #4
cj
Thanks, but right now all that is information overload. Folks here are
aware you can build a UI in 10 minutes. What they don't understand is
what another user put so clearly on another forum "10 minutes to put a
UI on a database table, 3 hours messing around trying to get it to work
correctly." I don't have time to read all that. Thankfully my
tinkering and these questions is helping.

Jack Jackson wrote:
On Wed, 05 Dec 2007 16:12:03 -0500, cj <cj@nospam.nospamwrote:
>As your probably aware the datagridview doesn't update it's source
datatable with changes to a cell until you move off that cell. Suppose
somone makes a change in a cell of my datagridview then clicks to go
elsewhere in the program--how can I be assured that change is
transmitted back to the source datatable?

One possibility is to force the changes to be made immediately,
although that won't work usefully if you have validation on the cell.

There is a lot of info about DataGridView here:
<http://www.windowsclient.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc>

Section 3.2 describes the process for a checkbox column, and there is
a code snippet here
<http://207.46.236.188/MSDN/ShowPost.aspx?PostID=2105950&SiteID=1>

Googling for CurrentCellDirtyStateChanged has a number of hits, many
of which are not working at the moment but they may work later.

There is also some information here:
<http://www.msdner.com/dev-archive/106/2-7-1062147.shtm>
Dec 6 '07 #5
cj
Yes, I find that does work but due to other situations in the code it
wasn't immediately apparent. I think with some rearranging it will do.

Cor Ligthert[MVP] wrote:
cj,

Call the EndEdit on the datasource.

Cor
>As your probably aware the datagridview doesn't update it's source
datatable with changes to a cell until you move off that cell.
Suppose somone makes a change in a cell of my datagridview then clicks
to go elsewhere in the program--how can I be assured that change is
transmitted back to the source datatable?
Dec 6 '07 #6
cj
Linda, sorry this pretty much goes over my head. Cor and some playing
around on my part have been able to make this a non-issue now. Thanks
anyway.

Linda Liu[MSFT] wrote:
Hi Chris,

When we select and type in the current cell in a DataGridView, the editing
control attached to the current cell is shown and the current cell is in
edit mode. If you click on another form in the application, only one event
is fired, i.e. the current editing control's LostFocus event.

So we could subscribe this event to get notified when the user clicks to go
elsewhere in the application so as to apply the changes in the current cell
back to the underlying data source.

The following is a sample to do this:

Private Sub DataGridView1_CellValidated(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellValidated
If (Me.DataGridView1.EditingControl IsNot Nothing) Then
RemoveHandler DataGridView1.EditingControl.LostFocus, AddressOf
Control_LostFocus
End If
End Sub

Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs)
Handles DataGridView1.EditingControlShowing
AddHandler e.Control.LostFocus, AddressOf Control_LostFocus
End Sub

Sub Control_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
If (Me.DataGridView1.IsCurrentCellInEditMode) Then
RemoveHandler Me.DataGridView1.EditingControl.LostFocus,
AddressOf Control_LostFocus
Me.DataGridView1.EndEdit()
End If
End Sub

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Dec 6 '07 #7
Linda,

AFAIK does the push of a button not fire the lostfocus event. Armin can much
better tell this then me, however this has been forever with Microsoft
controls.

Cor

Dec 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8474
by: JochenZ | last post by:
Hello, I have a DataGrid(View) and a DataTable. The DataTable is displayed in the DataGridView: dataGridView.DataSource = theTable; The user is allowed to select some rows and then the...
0
1271
by: JochenZ | last post by:
Hello, I have a DataGrid(View) and a DataTable. The DataTable is displayed in the DataGridView. The user is allowed to select some rows and then the following snippet updates some values in the...
2
1388
by: Simon Harvey | last post by:
Hi all, Is there any easy way to check a field for calues that have changed on a post back. So the page is sent to the user, the user changes some values and I need to know which ones...
5
1812
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is...
1
4259
by: cc | last post by:
Hi, using the DataGridView (.NET 2005) : I have a row currently selected in the Grid (say the 3rd row showing 'Product3') Now, when I click on a column to sort the records is the 'Product3'...
11
27269
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
2
20220
by: David Jackson | last post by:
Hello, I have an unbound DataGridView of which one of the columns is a ComboBox colum containing category data, plus an additional option called <newSo when the ComboBox is dropped down it looks...
1
1829
by: hughwarrington | last post by:
Hi there, I'd like to detect when the user resizes a column on a DataGridView by dragging the separator situated between columns. There is the ColumnWidthChanged event, but I can't find a way of...
1
2763
by: Arved Sandstrom | last post by:
This seems to be something so simple that none of the hundred-odd tutorials and forum threads that I have looked at (:-)) apparently thinks it's a problem. In a nutshell, I have two...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.