473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DataGrid EndCurrentEdit Problem persists...

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 (GridRemarks)
It is databound like this

GridRemarks.Datasource = mainDatasource ' a shortcut to
myDataSet.tblPersons.DefaultView
GridRemarks.DataMember ="tblPersons_tblRemarks" ' The name of the parent
detail relation
And it works fine

THE PROBLEM: But before I save I would like to end the current edits.
So I tried like this
Dim bmRemarks As BindingManagerBase = BindingContext(mainDataSource,
"tblPersons_tblRemarks")
bmRemarks.EndCurrentEdit()

And like this
Me.BindingContext(GridRemarks.DataSource,
GridRemarks.DataMember).EndCurrentEdit()

But to no avail.
I do not get any errors. It just does not end the current edit.
And my Dataset.HasChanges test is (of course) negative

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks.CurrentCell
Dim bm As BindingManagerBase = _
BindingContext(Me.GridRemarks.DataSource, Me.GridRemarks.DataMember)
Dim drv As DataRowView = CType(bm.Current, DataRowView)
Debug.WriteLine("Værdi: " & drv(myDataGridCell.ColumnNumber))
Debug.WriteLine("Row: " & myDataGridCell.RowNumber)

And it works fine and writes the correct values to the debug window

So I guess the bindingmanagerbase is correct. It just will not end the
currentedit

Any suggestions?

TIA

Jan

Nov 21 '05 #1
6 2029
Hi,

Take a look at the datagrids endedit method.
http://msdn.microsoft.com/library/de...dedittopic.asp

Ken
----------------------
"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:uU**************@TK2MSFTNGP15.phx.gbl...
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 (GridRemarks)
It is databound like this

GridRemarks.Datasource = mainDatasource ' a shortcut to
myDataSet.tblPersons.DefaultView
GridRemarks.DataMember ="tblPersons_tblRemarks" ' The name of the parent
detail relation
And it works fine

THE PROBLEM: But before I save I would like to end the current edits.
So I tried like this
Dim bmRemarks As BindingManagerBase = BindingContext(mainDataSource,
"tblPersons_tblRemarks")
bmRemarks.EndCurrentEdit()

And like this
Me.BindingContext(GridRemarks.DataSource,
GridRemarks.DataMember).EndCurrentEdit()

But to no avail.
I do not get any errors. It just does not end the current edit.
And my Dataset.HasChanges test is (of course) negative

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks.CurrentCell
Dim bm As BindingManagerBase = _
BindingContext(Me.GridRemarks.DataSource, Me.GridRemarks.DataMember)
Dim drv As DataRowView = CType(bm.Current, DataRowView)
Debug.WriteLine("Værdi: " & drv(myDataGridCell.ColumnNumber))
Debug.WriteLine("Row: " & myDataGridCell.RowNumber)

And it works fine and writes the correct values to the debug window

So I guess the bindingmanagerbase is correct. It just will not end the
currentedit

Any suggestions?

TIA

Jan


Nov 21 '05 #2
Hi Ken
Thanks for answering.
I used
GridRemarks.EndEdit(BemaerkningColHeader, Bemaerkninger.CurrentRowIndex,
False)
If dataset.HasChanges = False Then
MsgBox("no changes")
Exit Sub
End If

Strangely enough it does end the edit but the dataset.haschanges() returns
false.
I have to click somewhere else to make the dataset register the change
So I inserted a txtSomething.Focus(). I can live with this hack though not
completely satisfying.

Best regards

Jan
"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i en meddelelse
news:%2***************@TK2MSFTNGP14.phx.gbl...
Hi,

Take a look at the datagrids endedit method.
http://msdn.microsoft.com/library/de...dedittopic.asp

Ken
----------------------
"Jan Nielsen" <Re**************@tiscali.dk> wrote in message
news:uU**************@TK2MSFTNGP15.phx.gbl...
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 (GridRemarks)
It is databound like this

GridRemarks.Datasource = mainDatasource ' a shortcut to
myDataSet.tblPersons.DefaultView
GridRemarks.DataMember ="tblPersons_tblRemarks" ' The name of the parent
detail relation
And it works fine

THE PROBLEM: But before I save I would like to end the current edits.
So I tried like this
Dim bmRemarks As BindingManagerBase = BindingContext(mainDataSource,
"tblPersons_tblRemarks")
bmRemarks.EndCurrentEdit()

And like this
Me.BindingContext(GridRemarks.DataSource,
GridRemarks.DataMember).EndCurrentEdit()

But to no avail.
I do not get any errors. It just does not end the current edit.
And my Dataset.HasChanges test is (of course) negative

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks.CurrentCell
Dim bm As BindingManagerBase = _
BindingContext(Me.GridRemarks.DataSource, Me.GridRemarks.DataMember)
Dim drv As DataRowView = CType(bm.Current, DataRowView)
Debug.WriteLine("Værdi: " & drv(myDataGridCell.ColumnNumber))
Debug.WriteLine("Row: " & myDataGridCell.RowNumber)

And it works fine and writes the correct values to the debug window

So I guess the bindingmanagerbase is correct. It just will not end the
currentedit

Any suggestions?

TIA

Jan

Nov 21 '05 #3
Jan,

I thought that your question was another one, that i can not resolve.
(Databinding to a column of a related table).

However I think that this one will go.
DirectCast(BindingContext(ds, "ParentTableName.RelationName"),
CurrencyManager).EndCurrentEdit()

I hope this helps,

Cor
Nov 21 '05 #4
Hi Cor
Thanks for answering (again again)
Unfortunately this does not help.
I'll stick with Kens solution.
I have tried a lot of possible combinations of
bindingcontext.EndCurrentEdit() and none of them worked.
It seems to me that if you use EndCurrentEdit on a datagrids bindingcontext,
it does not end the current edit in the datagrid.
It looks to me like you have to use datagrid.EndEdit()

Best regards

Jan

"Cor Ligthert" <no************@planet.nl> skrev i en meddelelse
news:eC**************@TK2MSFTNGP15.phx.gbl...
Jan,

I thought that your question was another one, that i can not resolve.
(Databinding to a column of a related table).

However I think that this one will go.
DirectCast(BindingContext(ds, "ParentTableName.RelationName"),
CurrencyManager).EndCurrentEdit()

I hope this helps,

Cor

Nov 21 '05 #5
I tried this in another project where the datagrid was bound direct to a
single table and there it worked fine!
I tested a bit further and found out that it works if I push _a button_ with
the
BindingContext(ds, "ParentTableName.RelationName"),
CurrencyManager).EndCurrentEdit()
code
But it does not work if it is called from my _toolbarbutton_. Maybe because
the toolbarbutton does not remove focus from the datagrid?
Jan

"Cor Ligthert" <no************@planet.nl> skrev i en meddelelse
news:eC**************@TK2MSFTNGP15.phx.gbl...
Jan,

I thought that your question was another one, that i can not resolve.
(Databinding to a column of a related table).

However I think that this one will go.
DirectCast(BindingContext(ds, "ParentTableName.RelationName"),
CurrencyManager).EndCurrentEdit()

I hope this helps,

Cor

Nov 21 '05 #6
Jan,

I tested this and in my opinion it did work, here is the test, it needs
three datagrids and a button on a form.
\\\
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
CreateDs(ds)
DataGrid1.DataSource = ds
DataGrid2.DataSource = ds
DataGrid3.DataSource = ds.Tables("Persons")
DataGrid1.DataMember = "Countries"
DataGrid2.DataMember = "Countries.RPersons"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
DirectCast(BindingContext(ds, "Countries.RPersons"),
CurrencyManager).EndCurrentEdit()
End Sub

'To have a testable class
Private Sub CreateDs(ByVal ds As DataSet)
Dim dtName As New DataTable("Persons")
Dim dcName As New DataColumn("Name")
Dim dcCountry As New DataColumn("Country")
Dim dcState As New DataColumn("State")
dtName.Columns.Add(dcName)
dtName.Columns.Add(dcCountry)
dtName.Columns.Add(dcState)
ds.Tables.Add(dtName)
For i As Integer = 0 To 5
Dim dr As DataRow = dtName.NewRow
dtName.Rows.Add(dr)
Next
dtName.Rows(0).ItemArray = New Object() _
{"Herfried K. Wagner", "EU", "Austria"}
dtName.Rows(1).ItemArray = New Object() _
{"Ken Tucker", "US", "Florida"}
dtName.Rows(2).ItemArray = New Object() _
{"CJ Taylor", "US", "Illinois"}
dtName.Rows(3).ItemArray = New Object() _
{"Terry Burns", "EU", "UK"}
dtName.Rows(4).ItemArray = New Object() _
{"Jay B Harlow", "US", "New York"}
dtName.Rows(5).ItemArray = New Object() _
{"Cor Ligthert", "EU", "Holland"}
Dim dtCountry As New DataTable("Countries")
dcCountry = New DataColumn("Country")
dtCountry.Columns.Add(dcCountry)
ds.Tables.Add(dtCountry)
For i As Integer = 0 To 1
Dim dr As DataRow = dtCountry.NewRow
dtCountry.Rows.Add(dr)
Next
dtCountry.Rows(0)(0) = "EU"
dtCountry.Rows(1)(0) = "US"
Dim drlStates As New DataRelation _
("RPersons", ds.Tables("Countries").Columns("Country"), _
ds.Tables("Persons").Columns("Country"))
ds.Relations.Add(drlStates)
End Sub
////

I hope this helps,

Cor
"Jan Nielsen" <Re**************@tiscali.dk>
Hi Cor
Thanks for answering (again again)
Unfortunately this does not help.
I'll stick with Kens solution.
I have tried a lot of possible combinations of
bindingcontext.EndCurrentEdit() and none of them worked.
It seems to me that if you use EndCurrentEdit on a datagrids
bindingcontext, it does not end the current edit in the datagrid.
It looks to me like you have to use datagrid.EndEdit()

Best regards

Jan

"Cor Ligthert" <no************@planet.nl> skrev i en meddelelse
news:eC**************@TK2MSFTNGP15.phx.gbl...
Jan,

I thought that your question was another one, that i can not resolve.
(Databinding to a column of a related table).

However I think that this one will go.
DirectCast(BindingContext(ds, "ParentTableName.RelationName"),
CurrencyManager).EndCurrentEdit()

I hope this helps,

Cor


Nov 21 '05 #7

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

Similar topics

6
by: BFX | last post by:
Hi All, I have datagrid with binding on dataset this.grdMachineType.DataMember = "MachineTypes"; this.grdMachineType.DataSource = this.dsMachineTypes; After append new row in datagrid i...
0
by: Junkguy | last post by:
I need to be able to tell if the blank row of a DataGrid has been edited or not. In a DataGrid, you may notice that if you click on the asterisk row, the asterisk will change to a triangle, but...
2
by: ChrisM | last post by:
Can anyone please tell me what I'm doing wrong here. I have a Windows Form with a DataGrid on it, and I'm having real problems with the Sorting. It is easy to reproduce the problem I have. If...
4
by: TT (Tom Tempelaere) | last post by:
Hi, Suppose there is a DataGrid on a form bound to a DataTable. When a user is editing a cell without leaving the cell, and then closes the form, the value is not updated to the underlying data...
20
by: MadCrazyNewbie | last post by:
Hey group, I keep getting the following error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at...
3
by: elziko | last post by:
I have a DataTable bound to a DataGrid. When a user clicks on a row on the DataGrid I use: MyDataTable.Rows(MyDatagrid.CurrentRowIndex).Item(0) to do some work with the value in the first cell...
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...
12
by: Art | last post by:
Hi, I need help -- again -- I have a DataGrid with a DataTable as its source. It displays wonderfully when I put in some test data (withinin the code). Now, I'd like to change one of the...
1
by: Agnes | last post by:
my datagrid is bind to the table, I need to check clear when the user didn't input the figure. my code list as follow. when the datagrid got less then 100 tables, the code works, However, when it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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
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...

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.