I have a windows forms datagrid and I would like to be able to recognize
when changes have been made in order to perform the update. I tried the
following, which works well, but only if the user changes rows at some
point. If they enter the grid, change a cell, and then click close it does
not see the change. The same holds true if they enter the grid, change a
cell, arrow right or left to a different cell and change that value. If
they arrow up or down it sees the dataset as having changes.
What am I missing? I don't want to rely on the user having to press enter
or selecting a different row after making their update.
Thanks!
--------------------Code---------------------------------
Dim blnDataChanged As Boolean = False
Dim dt As DataTable
dt = ds.Tables("tblCIP").GetChanges
If dt Is Nothing Then
Return False
Else
Dim Row As DataRow
Dim intColumn As Integer
For Each Row In dt.Rows
Select Case Row.RowState
Case DataRowState.Added
blnDataChanged = True
Case DataRowState.Deleted
blnDataChanged = True
Case DataRowState.Modified
For intColumn = 0 To dt.Columns.Count - 1
If Not IsDBNull(Row(intColumn, DataRowVersion.Original)) And Not
IsDBNull(Row(intColumn, DataRowVersion.Current)) Then
If Row(intColumn, DataRowVersion.Original) <> Row(intColumn,
DataRowVersion.Current) Then
blnDataChanged = True
Exit For
End If
End If
Next
End Select
If blnDataChanged Then Exit For
Next
Return blnDataChanged
end If 2 1657
Also another issue along the same lines....
If the datagrid is loaded with no rows, then a new row is added by typing in
the bottom empty 'add new' row, then the row is changed (required - see
below) the code I detailed below WILL see the change made. Then when I
perform an update - odaCIP.Update(DsCIP, "tblCIP") - that new row isn't
added. If the dataset was loaded with multiple existing rows, it will add
the new row added using the same method.
Thanks for any help!
"Brian Hoops" <bhoops.remove_me@and_me.stoughtonutilities.com> wrote in
message news:eY**************@TK2MSFTNGP03.phx.gbl... I have a windows forms datagrid and I would like to be able to recognize when changes have been made in order to perform the update. I tried the following, which works well, but only if the user changes rows at some point. If they enter the grid, change a cell, and then click close it does not see the change. The same holds true if they enter the grid, change a cell, arrow right or left to a different cell and change that value. If they arrow up or down it sees the dataset as having changes.
What am I missing? I don't want to rely on the user having to press enter or selecting a different row after making their update.
Thanks!
--------------------Code--------------------------------- Dim blnDataChanged As Boolean = False Dim dt As DataTable
dt = ds.Tables("tblCIP").GetChanges
If dt Is Nothing Then Return False Else Dim Row As DataRow Dim intColumn As Integer For Each Row In dt.Rows Select Case Row.RowState Case DataRowState.Added blnDataChanged = True Case DataRowState.Deleted blnDataChanged = True Case DataRowState.Modified For intColumn = 0 To dt.Columns.Count - 1 If Not IsDBNull(Row(intColumn, DataRowVersion.Original)) And Not IsDBNull(Row(intColumn, DataRowVersion.Current)) Then If Row(intColumn, DataRowVersion.Original) <> Row(intColumn, DataRowVersion.Current) Then blnDataChanged = True Exit For End If End If Next End Select
If blnDataChanged Then Exit For Next
Return blnDataChanged end If
try this before you call the update:
me.bindingcontext(DsCIP,"tblCIP").endcurrentedits
I may or may not have a typo somewhere for I can't quite recall what the
exact clause was.
BTW, it's better to use the datatable.getchanges to get a table of changes
to do the updates then to use the table itself.
"Brian Hoops" <bhoops.remove_me@and_me.stoughtonutilities.com> wrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl... Also another issue along the same lines....
If the datagrid is loaded with no rows, then a new row is added by typing in the bottom empty 'add new' row, then the row is changed (required - see below) the code I detailed below WILL see the change made. Then when I perform an update - odaCIP.Update(DsCIP, "tblCIP") - that new row isn't added. If the dataset was loaded with multiple existing rows, it will add the new row added using the same method.
Thanks for any help!
"Brian Hoops" <bhoops.remove_me@and_me.stoughtonutilities.com> wrote in message news:eY**************@TK2MSFTNGP03.phx.gbl...I have a windows forms datagrid and I would like to be able to recognize when changes have been made in order to perform the update. I tried the following, which works well, but only if the user changes rows at some point. If they enter the grid, change a cell, and then click close it does not see the change. The same holds true if they enter the grid, change a cell, arrow right or left to a different cell and change that value. If they arrow up or down it sees the dataset as having changes.
What am I missing? I don't want to rely on the user having to press enter or selecting a different row after making their update.
Thanks!
--------------------Code--------------------------------- Dim blnDataChanged As Boolean = False Dim dt As DataTable
dt = ds.Tables("tblCIP").GetChanges
If dt Is Nothing Then Return False Else Dim Row As DataRow Dim intColumn As Integer For Each Row In dt.Rows Select Case Row.RowState Case DataRowState.Added blnDataChanged = True Case DataRowState.Deleted blnDataChanged = True Case DataRowState.Modified For intColumn = 0 To dt.Columns.Count - 1 If Not IsDBNull(Row(intColumn, DataRowVersion.Original)) And Not IsDBNull(Row(intColumn, DataRowVersion.Current)) Then If Row(intColumn, DataRowVersion.Original) <> Row(intColumn, DataRowVersion.Current) Then blnDataChanged = True Exit For End If End If Next End Select
If blnDataChanged Then Exit For Next
Return blnDataChanged end If
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dmitry Akselrod |
last post by:
Hi,
I am using a standard .NET 1.0 Datagrid. Actually, I am using two, bound to
a master-detail relationship. Both DataGrids are bound to a datasource. I
have the MSDN version of the...
|
by: Skip |
last post by:
Hi,
This might be the easiest question ever but I can't seem to find how to do
it: I have a DataGrid that's linked to an instance of IList (actually, it's
an ArrayList). On load, there's...
|
by: Glenn Owens |
last post by:
I have a DataGrid web control which I've dynamically populated with
template columns to be used for bulk-editting. Generally, all of the
columns are textbox and/or dropdownlist child controls.
...
|
by: Manish |
last post by:
Hey folks
I am having a weird problem in ASP .Net. My page is in C#. I have a
datagrid, which populates based on selection in drop down box on ASP
page. This datagrid has template textbox colum in...
|
by: tafs7 |
last post by:
Hello,
I have a custom datagrid control that works great. But I was thinking
about adding some functionality to it. Currently, I use the datagrid
to display one record at a time, and with item...
| |
by: Daniel Walzenbach |
last post by:
Hi,
I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
|
by: Warex |
last post by:
Hello I am having a problem with using the datagrid.
I am attaching my data through a dataset via code to a
datagridview.datasource.
All if fine except if I make any changes to the datagrid the...
|
by: gtyler |
last post by:
When you make changes to a DataGrid a picture of a Pencil appears on the right hand side. As I understand it, the DataSource is not updated until you move off that row and the Pencil disappears.
...
|
by: gyap88 |
last post by:
Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz...
|
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,...
|
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...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
| |