Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem ending edit in dataGrid before saving underlying dataTable

0 views
Skip to first unread message

Alastair Bell

unread,
Aug 2, 2003, 7:36:54 AM8/2/03
to
I am having trouble forcing a dataGrid to save the current row prior to
saving the underlying dataTable.

I have a windows form with a dataGrid that I bind to a dataTable.
I have a menu on the form that is used to save the changes in the dataTable
back to the database.

I am finding that if the user is editing a row in the dataGrid and then
clicks on the Save menu before moving to another row, the current changes
being made in the row are not saved back to the database.

By putting an event handler on the underlying dataTable I can see that the
rowChanged is not firing before the code in the menu.click event (where the
code to save the dataTable resides), in fact the rowChanged event does not
fire at all.

If I attach the code to save the dataTable to a button instead of a menu
then it works fine. The dataTable rowChanged event fires (as the changes in
the current row in the grid are written to the dataTable) and the current
changes are written back to the dataBase.

I have tried using the CurrencyManager.EndCurrentEdit method to try and
force the changes before the dataTable is saved, but this does not work.


Would appreciate any help with this problem
Alastair


Lion Shi

unread,
Aug 4, 2003, 6:04:16 AM8/4/03
to
Hello Alastair,

It is caused by the DataGrid cell still held the focus when the menu is
clicked. You may try the following two ways to workaround it:

1. Call the DataGrid.EndEdit method in the menu handler.
2. Set the focus to other control before saving data.

I hope this helps you.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ¨C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------
| From: "Alastair Bell" <alastai...@tchibo.co.uk>
| Subject: Problem ending edit in dataGrid before saving underlying
dataTable
| Date: Sat, 2 Aug 2003 12:36:54 +0100
| Lines: 29
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <eVcIMoOW...@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms.databinding
| NNTP-Posting-Host: host217-35-102-234.in-addr.btopenworld.com
217.35.102.234
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms.databinding:3635
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms.databinding

Alastair Bell

unread,
Aug 4, 2003, 12:08:34 PM8/4/03
to
Lion

Thankyou for that suggestion, I have tried both techniques
and they work. The one I prefer is the dataGrid.EndEdit
method as it does not require putting another control on
the form (just to receive focus).

Therefore I added 2 lines of code as shown below and it
works.
Dim lDgc As DataGridColumnStyle = Me.dGrid1.TableStyles
(0).GridColumnStyles(Me.dGrid1.CurrentCell.ColumnNumber)

Me.dGrid1.EndEdit(lDgc,Me.dGrid1.CurrentCell.RowNumber,
False)

The question I have, is whether there is a more elegant
way to obtain a reference to the DataGridColumnStyle of
the cell being edited.

The example above uses the grid's TableStyles collection
to get to the DataGridColumnStyle . This raises 2
potential problems.

1) If a grid is populated without defining a
DataGridTableStyle, a default DataGridTableStyle is used
and this is not placed in the TableStyles collection,
hence any reference to this collection raises an exception.

2) In grids with more than one table in the dataSource it
may be difficult to find the DataGridTableStyle for the
table currently being edited.

Alastair

>.
>

Lion Shi

unread,
Aug 4, 2003, 10:42:12 PM8/4/03
to
Hello Alastair,

Yes, the EndEdit method is limitted with some situations. That's why I
provided the second way. However, the following code may resolve some
issues, but not all:

foreach(DataGridTableStyle myGridStyle in myGrid.TableStyles)
{
foreach(DataGridColumnStyle myColumnStyle in myGridStyle.GridColumnStyles)
{
for(int row = 0; row < gridrows; row++)
{
myGridStyle.EndEdit(myColumnStyle, row, false);
}
}
}

Hope this helps.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer

Get Secure! www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------

| Content-Class: urn:content-classes:message
| From: "Alastair Bell" <alastai...@tchibo.co.uk>
| Sender: "Alastair Bell" <alastai...@tchibo.co.uk>
| References: <eVcIMoOW...@TK2MSFTNGP11.phx.gbl>
<EmYxP$mWDHA...@cpmsftngxa06.phx.gbl>
| Subject: RE: Problem ending edit in dataGrid before saving underlying
dataTable
| Date: Mon, 4 Aug 2003 09:08:34 -0700
| Lines: 134
| Message-ID: <001e01c35aa2$a81ef9f0$a401...@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: quoted-printable
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNaoqgeyUGsT9wTS6i2Oc2q0HCaXA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms.databinding
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms.databinding:3647
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms.databinding

Ulrich Sprick

unread,
Aug 8, 2003, 4:41:42 AM8/8/03
to
Hi Alistair,

the data table (or it's data row view) has an EndEdit() method, which invokes the EndEdit() method of all bound controls. So you
don't have to care which control currently has the focus...

ulli

"Alastair Bell" <alastai...@tchibo.co.uk> schrieb im Newsbeitrag news:eVcIMoOW...@TK2MSFTNGP11.phx.gbl...

0 new messages