By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

DataGrid EndCurrentEdit Problem persists...

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.