473,775 Members | 2,672 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 6294
On Wed, 05 Dec 2007 16:12:03 -0500, cj <cj@nospam.nosp amwrote:
>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.windowsclie nt.net/Samples/Go%20To%20Marke t/DataGridView/DataGridView%20 FAQ.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?P ostID=2105950&S iteID=1>

Googling for CurrentCellDirt yStateChanged 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_C ellValidated(By Val sender As Object, ByVal e As
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.C ellValidated
If (Me.DataGridVie w1.EditingContr ol IsNot Nothing) Then
RemoveHandler DataGridView1.E ditingControl.L ostFocus, AddressOf
Control_LostFoc us
End If
End Sub

Private Sub DataGridView1_E ditingControlSh owing(ByVal sender As Object,
ByVal e As System.Windows. Forms.DataGridV iewEditingContr olShowingEventA rgs)
Handles DataGridView1.E ditingControlSh owing
AddHandler e.Control.LostF ocus, AddressOf Control_LostFoc us
End Sub

Sub Control_LostFoc us(ByVal sender As Object, ByVal e As EventArgs)
If (Me.DataGridVie w1.IsCurrentCel lInEditMode) Then
RemoveHandler Me.DataGridView 1.EditingContro l.LostFocus,
AddressOf Control_LostFoc us
Me.DataGridView 1.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.nosp amwrote:
>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.windowsclie nt.net/Samples/Go%20To%20Marke t/DataGridView/DataGridView%20 FAQ.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?P ostID=2105950&S iteID=1>

Googling for CurrentCellDirt yStateChanged 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_C ellValidated(By Val sender As Object, ByVal e As
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.C ellValidated
If (Me.DataGridVie w1.EditingContr ol IsNot Nothing) Then
RemoveHandler DataGridView1.E ditingControl.L ostFocus, AddressOf
Control_LostFoc us
End If
End Sub

Private Sub DataGridView1_E ditingControlSh owing(ByVal sender As Object,
ByVal e As System.Windows. Forms.DataGridV iewEditingContr olShowingEventA rgs)
Handles DataGridView1.E ditingControlSh owing
AddHandler e.Control.LostF ocus, AddressOf Control_LostFoc us
End Sub

Sub Control_LostFoc us(ByVal sender As Object, ByVal e As EventArgs)
If (Me.DataGridVie w1.IsCurrentCel lInEditMode) Then
RemoveHandler Me.DataGridView 1.EditingContro l.LostFocus,
AddressOf Control_LostFoc us
Me.DataGridView 1.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
8516
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 following snippet updates some values in the selected rows:
0
1281
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 selected rows: foreach (DataGridViewRow row in dataGridView.SelectedRows) { row.Cells.Value = someCalculatedValue1; row.Cells.Value = someCalculatedValue2;
2
1405
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 changed. Is the only way to do this to go through all the fields and check them against their old values. In which case, would I need to store the values in
5
1837
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 populated) is from several different tables. To the user, of course, this is not seen. Scenario: After the page is populated, assume a change is made to the form and the user hits update. The page then goes back, reads the database for that record...
1
4272
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' row located as first row in the Grid but not selected (highlighted) anymore. The position of the selected (highlighted)-row doesn't change and is still located on the 3rd row, thus showing a dfifferent product. I don't want
11
27321
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 Windows Forms program with a DataGridView and a BindingSource added to a form. Here is the code I'm using to populate the grid: Dim CRClassesTableAdapter As SqlDataAdapter Dim CRClassesTable As New DataTable()
2
20245
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 like this <new> First Second Third
1
1849
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 distinguishing whether this was the result of the user dragging the separator, or one of the many other programmatic causes (columns being added/removed, my own auto-resizing code etc.). Any ideas? Many thanks in advance, Hugh
1
2781
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 DataGridViews. Each has a BindingSource (and a BindingNavigator). The first view populates successfully based upon a Linq to SQL query in the Form Load (that is, the query is assigned to the DataSource of that view's BindingSource, and the BindingSource is...
0
9622
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6719
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4021
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 we have to send another system
2
3613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2855
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.