473,811 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Dat asource = mainDatasource ' a shortcut to
myDataSet.tblPe rsons.DefaultVi ew
GridRemarks.Dat aMember ="tblPersons_tb lRemarks" ' 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 BindingManagerB ase = BindingContext( mainDataSource,
"tblPersons_tbl Remarks")
bmRemarks.EndCu rrentEdit()

And like this
Me.BindingConte xt(GridRemarks. DataSource,
GridRemarks.Dat aMember).EndCur rentEdit()

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

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks. CurrentCell
Dim bm As BindingManagerB ase = _
BindingContext( Me.GridRemarks. DataSource, Me.GridRemarks. DataMember)
Dim drv As DataRowView = CType(bm.Curren t, DataRowView)
Debug.WriteLine ("Værdi: " & drv(myDataGridC ell.ColumnNumbe r))
Debug.WriteLine ("Row: " & myDataGridCell. RowNumber)

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

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

Any suggestions?

TIA

Jan

Nov 21 '05 #1
6 2052
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******** ******@TK2MSFTN GP15.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.Dat asource = mainDatasource ' a shortcut to
myDataSet.tblPe rsons.DefaultVi ew
GridRemarks.Dat aMember ="tblPersons_tb lRemarks" ' 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 BindingManagerB ase = BindingContext( mainDataSource,
"tblPersons_tbl Remarks")
bmRemarks.EndCu rrentEdit()

And like this
Me.BindingConte xt(GridRemarks. DataSource,
GridRemarks.Dat aMember).EndCur rentEdit()

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

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks. CurrentCell
Dim bm As BindingManagerB ase = _
BindingContext( Me.GridRemarks. DataSource, Me.GridRemarks. DataMember)
Dim drv As DataRowView = CType(bm.Curren t, DataRowView)
Debug.WriteLine ("Værdi: " & drv(myDataGridC ell.ColumnNumbe r))
Debug.WriteLine ("Row: " & myDataGridCell. RowNumber)

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

So I guess the bindingmanagerb ase 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.End Edit(Bemaerknin gColHeader, Bemaerkninger.C urrentRowIndex,
False)
If dataset.HasChan ges = False Then
MsgBox("no changes")
Exit Sub
End If

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

Best regards

Jan
"Ken Tucker [MVP]" <vb***@bellsout h.net> skrev i en meddelelse
news:%2******** *******@TK2MSFT NGP14.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******** ******@TK2MSFTN GP15.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.Dat asource = mainDatasource ' a shortcut to
myDataSet.tblPe rsons.DefaultVi ew
GridRemarks.Dat aMember ="tblPersons_tb lRemarks" ' 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 BindingManagerB ase = BindingContext( mainDataSource,
"tblPersons_tbl Remarks")
bmRemarks.EndCu rrentEdit()

And like this
Me.BindingConte xt(GridRemarks. DataSource,
GridRemarks.Dat aMember).EndCur rentEdit()

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

Now I have tried to write code like this:
Dim myDataGridCell As DataGridCell = Me.GridRemarks. CurrentCell
Dim bm As BindingManagerB ase = _
BindingContext( Me.GridRemarks. DataSource, Me.GridRemarks. DataMember)
Dim drv As DataRowView = CType(bm.Curren t, DataRowView)
Debug.WriteLine ("Værdi: " & drv(myDataGridC ell.ColumnNumbe r))
Debug.WriteLine ("Row: " & myDataGridCell. RowNumber)

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

So I guess the bindingmanagerb ase 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(Bind ingContext(ds, "ParentTableNam e.RelationName" ),
CurrencyManager ).EndCurrentEdi t()

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.EndEdi t()

Best regards

Jan

"Cor Ligthert" <no************ @planet.nl> skrev i en meddelelse
news:eC******** ******@TK2MSFTN GP15.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(Bind ingContext(ds, "ParentTableNam e.RelationName" ),
CurrencyManager ).EndCurrentEdi t()

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, "ParentTableNam e.RelationName" ),
CurrencyManager ).EndCurrentEdi t()
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******** ******@TK2MSFTN GP15.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(Bind ingContext(ds, "ParentTableNam e.RelationName" ),
CurrencyManager ).EndCurrentEdi t()

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(ByVa l sender As Object, ByVal e _
As System.EventArg s) Handles MyBase.Load
CreateDs(ds)
DataGrid1.DataS ource = ds
DataGrid2.DataS ource = ds
DataGrid3.DataS ource = ds.Tables("Pers ons")
DataGrid1.DataM ember = "Countries"
DataGrid2.DataM ember = "Countries.RPer sons"
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
DirectCast(Bind ingContext(ds, "Countries.RPer sons"),
CurrencyManager ).EndCurrentEdi t()
End Sub

'To have a testable class
Private Sub CreateDs(ByVal ds As DataSet)
Dim dtName As New DataTable("Pers ons")
Dim dcName As New DataColumn("Nam e")
Dim dcCountry As New DataColumn("Cou ntry")
Dim dcState As New DataColumn("Sta te")
dtName.Columns. Add(dcName)
dtName.Columns. Add(dcCountry)
dtName.Columns. Add(dcState)
ds.Tables.Add(d tName)
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("Coun tries")
dcCountry = New DataColumn("Cou ntry")
dtCountry.Colum ns.Add(dcCountr y)
ds.Tables.Add(d tCountry)
For i As Integer = 0 To 1
Dim dr As DataRow = dtCountry.NewRo w
dtCountry.Rows. Add(dr)
Next
dtCountry.Rows( 0)(0) = "EU"
dtCountry.Rows( 1)(0) = "US"
Dim drlStates As New DataRelation _
("RPersons", ds.Tables("Coun tries").Columns ("Country"), _
ds.Tables("Pers ons").Columns(" Country"))
ds.Relations.Ad d(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.EndEdi t()

Best regards

Jan

"Cor Ligthert" <no************ @planet.nl> skrev i en meddelelse
news:eC******** ******@TK2MSFTN GP15.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(Bind ingContext(ds, "ParentTableNam e.RelationName" ),
CurrencyManager ).EndCurrentEdi t()

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
1641
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 call this
0
1276
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 no "new" blank asterisked row will be added to the bottom *until* you type some data. How can I tell if you have begun to type data into this row or not? Here is the reason I need this. I need to call CurrencyManager.EndCurrentEdit() on a row...
2
368
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 you create a new Windows Application Put a DataGrid control on it. Put the following in the onload event of the form:
4
4271
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 source. How can I accomplish this? Thanks, --
20
2038
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 position 1." on the following line of code:
3
3374
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 for the currently selected row. However, when I delete a row (using the delete key oin the grid) and try and do the above on the row that has now taken the deleed roe's position in the grid I get the following exception:
2
1847
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 shortcut to myDataSet.tblPersons.DefaultView GridRemarks.DataMember ="tblPersons_tblRemarks" ' The name of the parent detail relation
12
1786
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 values in the Grid, and have the DataTable change. I've tried using a Validating (and Validated) event to display the changed data. It doesn't change. I've tried adding
1
1601
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 over 100 rows. it can't work. Does anything wrong with my code ? Please help P.S - I can't use delete since the user remove the unused record before save. Dim cm As CurrencyManager = Me.BindingContext(dsRvPvHeader,
0
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6889
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.