Delete a row from datagrid?

T

Tomer

How can I delete the row that the datagrid is showing?
Its not enought to use:

DS.Tables["thetable"].Rows[DG.CurrentRowIndex].Delete();

Because this way I can loose the right record position, for example if I have three records and I first delete the first record, then the CurrentRowIndex will not be corresponding with the table record number.

For now I use this line:

DS.Tables["thetable"].Rows.Find((object)KeyFieldLabel.Text).Delete();

KeyFieldLabel is binded to the tables' primary key.

But I need a better and simpler way to do this.

Thanks.
Tomer.
 
I

Ilya Tumanov [MS]

If you use DataTable as a data source for DataGrid, grid would be bound not
to the table itself, but to the table's default DataView
(table.DefaultView).
Rows in the DataView would match rows in the grid even if sorting/filtering
is used.

So, you should use DefaltView to access and modify data:

DS.Tables["thetable"].DefaultView.Delete(DG.CurrentRowIndex);

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Tomer" <[email protected]>
Subject: Delete a row from datagrid?
Date: Thu, 17 Jun 2004 12:22:54 +0200
Lines: 82
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_000C_01C45465.D08BA7E0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <Oq8W#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: bzq-165-146.dsl.bezeqint.net 62.219.165.146
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:55401
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

How can I delete the row that the datagrid is showing?
Its not enought to use:
DS.Tables["thetable"].Rows[DG.CurrentRowIndex].Delete();
Because this way I can loose the right record position, for example if I
have three records and I first delete the first record, then the
CurrentRowIndex will not be corresponding with the table record number.
For now I use this line:
DS.Tables["thetable"].Rows.Find((object)KeyFieldLabel.Text).Delete();
KeyFieldLabel is binded to the tables' primary key.
But I need a better and simpler way to do this.
Thanks.
Tomer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top