473,473 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagrid current row edits

VS2003
I am using a datagrid on a Windows form.
The user has 2 buttons: cancel the current changes (re-loads the dataset)
or update (updates the dataset).
The problem is that any edits in the current row are not included in the
update.
The user has to click out of that row before updating. If this is not done
and the 'current row' remains selected after the update, the user will see
the edited row and assume it has been included in the update.
I have tried moving the focus before updating and even EndEdit to try to
force the current row to accept any changes - but without success.

Has anyone got any suggestions?
Thanks in advance.
Jun 2 '06 #1
4 3434
Keith,
Can you post some of your code from the update event?

Jun 2 '06 #2
Here is the code from the form which includes the Toolbar button events and
the unsuccessful 'EndEdit'.

Private Sub dsLoad()
Me.ObjDsSupplierList.Clear()

Me.OleDbDataAdapter1.Fill(ObjDsSupplierList.Tables (0))

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

Dim dgtS As DataGridTableStyle = Me.dgdSuppliers.TableStyles(0)
'complete any edits

dgtS.DataGrid.EndEdit(dgtS.GridColumnStyles(Me.dgd Suppliers.CurrentCell.ColumnNumber), Me.dgdSuppliers.CurrentRowIndex, False)

Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 1
dsLoad()
Case 2
If ObjDsSupplierList.HasChanges() Then
Try
OleDbDataAdapter1.Update(ObjDsSupplierList)
Catch ex As Exception
MsgBox("There were errors in the data. The table has
not been updated." & vbCr & ex.Message)
End Try

End If
End Select
End Sub

"Charlie Brown" wrote:
Keith,
Can you post some of your code from the update event?

Jun 2 '06 #3
Hi,

I had this problem before, and I solved it with the following procedures:

=============================

Public Sub UpdateDatasource(ByVal OleDB As DataAdapter, ByVal grid As
GridControl, ByVal dataset11 As DataSet, ByVal TableName As String)
'Save the latest changes to the bound DataTable
Dim View As ColumnView = grid.KeyboardFocusView
View.CloseEditor() ' <=== VERY IMPORTANT Statement for any update
If Not View.UpdateCurrentRow() Then Return
'Update the database's table
DoUpdateTable(OleDB, dataset11.Tables(TableName))

'Update the database's table
End Sub

Public Sub DoUpdateTable(ByVal dataAdapter As DbDataAdapter, ByVal
dataTable As System.Data.DataTable)
dataAdapter.Update(dataTable)
End Sub

================================

I hope this helps you.

Regards

"Keith G" wrote:
Here is the code from the form which includes the Toolbar button events and
the unsuccessful 'EndEdit'.

Private Sub dsLoad()
Me.ObjDsSupplierList.Clear()

Me.OleDbDataAdapter1.Fill(ObjDsSupplierList.Tables (0))

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

Dim dgtS As DataGridTableStyle = Me.dgdSuppliers.TableStyles(0)
'complete any edits

dgtS.DataGrid.EndEdit(dgtS.GridColumnStyles(Me.dgd Suppliers.CurrentCell.ColumnNumber), Me.dgdSuppliers.CurrentRowIndex, False)

Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 1
dsLoad()
Case 2
If ObjDsSupplierList.HasChanges() Then
Try
OleDbDataAdapter1.Update(ObjDsSupplierList)
Catch ex As Exception
MsgBox("There were errors in the data. The table has
not been updated." & vbCr & ex.Message)
End Try

End If
End Select
End Sub

"Charlie Brown" wrote:
Keith,
Can you post some of your code from the update event?

Jun 3 '06 #4
Thanks for your response.
However, I don't recognise GridControl or ColumnView as Controls, Classes or
Members.
Are these controls in VS 2005? I'm using VS 2003.
There doesn't seem to be the equivalent to the KeyboardFocusView and
CloseEditor members in VS 2003 (which appears to be the key to including the
current row edits in the update)
...... or am I in the wrong discussion group?!!
"Moumen VB.NET 2003/2005 Developer" wrote:
Hi,

I had this problem before, and I solved it with the following procedures:

=============================

Public Sub UpdateDatasource(ByVal OleDB As DataAdapter, ByVal grid As
GridControl, ByVal dataset11 As DataSet, ByVal TableName As String)
'Save the latest changes to the bound DataTable
Dim View As ColumnView = grid.KeyboardFocusView
View.CloseEditor() ' <=== VERY IMPORTANT Statement for any update
If Not View.UpdateCurrentRow() Then Return
'Update the database's table
DoUpdateTable(OleDB, dataset11.Tables(TableName))

'Update the database's table
End Sub

Public Sub DoUpdateTable(ByVal dataAdapter As DbDataAdapter, ByVal
dataTable As System.Data.DataTable)
dataAdapter.Update(dataTable)
End Sub

================================

I hope this helps you.

Regards

"Keith G" wrote:
Here is the code from the form which includes the Toolbar button events and
the unsuccessful 'EndEdit'.

Private Sub dsLoad()
Me.ObjDsSupplierList.Clear()

Me.OleDbDataAdapter1.Fill(ObjDsSupplierList.Tables (0))

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

Dim dgtS As DataGridTableStyle = Me.dgdSuppliers.TableStyles(0)
'complete any edits

dgtS.DataGrid.EndEdit(dgtS.GridColumnStyles(Me.dgd Suppliers.CurrentCell.ColumnNumber), Me.dgdSuppliers.CurrentRowIndex, False)

Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 1
dsLoad()
Case 2
If ObjDsSupplierList.HasChanges() Then
Try
OleDbDataAdapter1.Update(ObjDsSupplierList)
Catch ex As Exception
MsgBox("There were errors in the data. The table has
not been updated." & vbCr & ex.Message)
End Try

End If
End Select
End Sub

"Charlie Brown" wrote:
Keith,
Can you post some of your code from the update event?

Jun 3 '06 #5

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

Similar topics

0
by: Frnak McKenney | last post by:
I have a (small) multi-table database application which allows edits, print reports, and has two scrolling screen displays which show information merged from multiple tables. I'm having trouble...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
0
by: Jim Heavey | last post by:
Hello, I have a datagrid that I have configured to bind to "table1". I created and "EditItemTemplate" which is also bound to "table1" except for two columns which I bound to "table2" and "table3"...
3
by: Richard | last post by:
I've seen articles on GotDotNet and elsewhere on how to put a ddl in a datagrid, and have been able to implement this technique. For a new item, among the datagrid columns there is the one ddl for...
2
by: Jan Nielsen | last post by:
Hi I have a parent detail relationship between two tables. The detail records are shown in a datagrid (GridRemarks) It is databound like this GridRemarks.Datasource = mainDatasource ' a...
6
by: Jan Nielsen | last post by:
Hi I asked this question some weeks ago, but have found no soluion yet, so I try again I have a parent detail relationship between two tables. The detail records are shown in a datagrid...
2
by: dbuchanan | last post by:
Where is the logic error that causes the attached code to adds two rows instead on one to the datagrid? The code correctly update the datasource with one row, but the datagrid gets two new rows....
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
4
by: _MC_ | last post by:
Hi, I'm unable to access values in my Datagrid. Datagrid thinks it hase only 1 Cell. So here it is: The Datagrid is binded in PageLoad, AutoGenerateColumns is false, Columns are added on...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...
0
agi2029
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.