|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid - recognizing changes madewhen 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 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! Show quoteHide quote "Brian Hoops" <bhoops.remove_me@and_me.stoughtonutilities.com> wrote in message news:eYk9o$qeGHA.3692@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. Show quoteHide quote "Brian Hoops" <bhoops.remove_me@and_me.stoughtonutilities.com> wrote in message news:%23E1dmSreGHA.4932@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:eYk9o$qeGHA.3692@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 >> >> > >
Possible to set/reference a property 'dynamically'?
How to run scheduler for more than one time in a day Parse String in Quotes as without Quotes Help with deleting a Row in a database network programming with vb Error that I can't figure out Update ODBC DSN Properties in VB.NET Code? Download a file from a secured Https Server textbox currency free tutorials |
|||||||||||||||||||||||