Delete DataRow in DataTable ?

J

jez

I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cur
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have any primary keys in
the table - even though I do. They're specified in a .xsd schema.

thanks, jez
 
A

Alex Yakhnin [MVP]

Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex
 
J

jez

nothing happens..

well it's not bound - bound. I just put the datasource of the datagrid equal
to one of my datatables. Should I bind it as well ? What's the difference ?
(bare in mind that I use a dataview as source as I first filer some rows
out)

Alex Yakhnin said:
Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex
-----Original Message-----
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts [dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cu
r
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber, (dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have any primary keys in
the table - even though I do. They're specified in a .xsd schema.

thanks, jez


.
 
A

Alex Yakhnin [MVP]

Let me get this straight... You get a DataSet from some
XML. Then you filter rows using DataView, and what do you
bind to the DataGrid? The result from DataView filtering?
Do you have related table in the DataSet?

-Alex
-----Original Message-----
nothing happens..

well it's not bound - bound. I just put the datasource of the datagrid equal
to one of my datatables. Should I bind it as well ? What's the difference ?
(bare in mind that I use a dataview as source as I first filer some rows
out)

Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex
-----Original Message-----
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts
[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cu
r
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts
[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't
have
any primary keys in
the table - even though I do. They're specified in
a .xsd
schema.
thanks, jez


.


.
 
J

jez

Hey Alex,

I "somehow" managed to solve my problem and use
productsTable.Rows.Remove(foundRow);

I'm still stuck with the ampersand-problem though.. maybe you've got some
idea about a C# method I could use ?

Alex Yakhnin said:
Let me get this straight... You get a DataSet from some
XML. Then you filter rows using DataView, and what do you
bind to the DataGrid? The result from DataView filtering?
Do you have related table in the DataSet?

-Alex
-----Original Message-----
nothing happens..

well it's not bound - bound. I just put the datasource of the datagrid equal
to one of my datatables. Should I bind it as well ? What's the difference ?
(bare in mind that I use a dataview as source as I first filer some rows
out)

Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex

-----Original Message-----
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] =
listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts
[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cu
r
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts [dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the
current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I
could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have
any primary keys in
the table - even though I do. They're specified in a .xsd
schema.

thanks, jez


.


.
 
A

Alex Yakhnin [MVP]

I "somehow" managed to solve my problem and use
productsTable.Rows.Remove(foundRow);

Glad it worked out for you...
I'm still stuck with the ampersand-problem though.. maybe you've got some
idea about a C# method I could use ?

Could you, please, re-iterate on this "ampersand-problem"?

-Alex
-----Original Message-----
Hey Alex,

I "somehow" managed to solve my problem and use
productsTable.Rows.Remove(foundRow);

I'm still stuck with the ampersand-problem though.. maybe you've got some
idea about a C# method I could use ?

Let me get this straight... You get a DataSet from some
XML. Then you filter rows using DataView, and what do you
bind to the DataGrid? The result from DataView filtering?
Do you have related table in the DataSet?

-Alex
-----Original Message-----
nothing happens..

well it's not bound - bound. I just put the datasource
of
the datagrid equal
to one of my datatables. Should I bind it as well ? What's the difference ?
(bare in mind that I use a dataview as source as I
first
filer some rows
out)

"Alex Yakhnin [MVP]" <[email protected]> wrote
in
message
Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex

-----Original Message-----
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] =
listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts
[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cu
r
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts [dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the
current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I
could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have
any primary keys in
the table - even though I do. They're specified in a .xsd
schema.

thanks, jez


.



.


.
 
M

Mark Johnson

Here you are adding a new row to your Table and then deleting it.
What you need is to get the DataRow you want to delete and delete it.

for (int i=0;i<productsTable.Rows.Count;i++)
{
if (productsTable.Rows[["product"].ToString()
==dataGridProducts[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.CurrentCell.ColumnNumber)+1].ToString())
{
productsTable.Rows.Delete();
productsTable.AcceptChanges();
}
} // for (int i=0;i<dview_UserMarkiert.Table.Count;i++)

Hope this helps.

Mark Johnson, Berlin Germany
(e-mail address removed)
 
I

Ilya Tumanov [MS]

Mark,

Here's another way to do it:

productsTable.DefaultView.Delete(dataGridProducts.CurrentRowIndex);

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Mark Johnson" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
References: <[email protected]>
Subject: Re: Delete DataRow in DataTable ?
Date: Fri, 16 Jan 2004 00:01:10 +0100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Lines: 60
Message-ID: <[email protected]>
Organization: Arcor
NNTP-Posting-Date: 16 Jan 2004 00:01:12 MET
NNTP-Posting-Host: 213.23.147.152
X-Trace: DXC=oBBQ;U7AQC:LL2:TY8[@n6Q5U85hF6f;4jW\KbG]kaM8eDdmR4DE3R<oRGdON<La03jLofn]
?Un[:Y:i@ie^9[=;S3`82`ie0m<
X-Complaints-To: (e-mail address removed)
Path: cpmsftngxa08.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-o
nline.de!t-online.de!newsfeed.arcor-online.net!newsread.arcor-online.net!new
s.arcor.de!not-for-mail
Xref: cpmsftngxa08.phx.gbl microsoft.public.dotnet.framework.compactframework:42767
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Here you are adding a new row to your Table and then deleting it.
What you need is to get the DataRow you want to delete and delete it.

for (int i=0;i<productsTable.Rows.Count;i++)
{
if (productsTable.Rows[["product"].ToString()
==dataGridProducts[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.CurrentCell.ColumnNumber)+1].ToString())
{
productsTable.Rows.Delete();
productsTable.AcceptChanges();
}
} // for (int i=0;i<dview_UserMarkiert.Table.Count;i++)

Hope this helps.

Mark Johnson, Berlin Germany
(e-mail address removed)



jez said:
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cur
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have any primary
keys
in
the table - even though I do. They're specified in a .xsd schema.

thanks, jez
 
J

jez

Ilya,

that looks like an interesting way to delete a row. Would it still work if I
were to filter out some rows in the dataGrid using RowFilter on a DataView ?
(so that the index of a row in a dataGrid would not correspond with the one
of its datatTable)

"Ilya Tumanov [MS]" said:
Mark,

Here's another way to do it:

productsTable.DefaultView.Delete(dataGridProducts.CurrentRowIndex);

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Mark Johnson" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
References: <[email protected]>
Subject: Re: Delete DataRow in DataTable ?
Date: Fri, 16 Jan 2004 00:01:10 +0100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Lines: 60
Message-ID: <[email protected]>
Organization: Arcor
NNTP-Posting-Date: 16 Jan 2004 00:01:12 MET
NNTP-Posting-Host: 213.23.147.152
X-Trace:
DXC=oBBQ;U7AQC:LL2:TY8[@n6Q5U85hF6f;4jW\KbG]kaM8eDdmR4DE3R<oRGdON<La03jLofn]
?Un[:Y:i@ie^9[=;S3`82`ie0m<
X-Complaints-To: (e-mail address removed)
Path:
cpmsftngxa08.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor-online.net!newsread.arcor-online.net!new
s.arcor.de!not-for-mail
Xref: cpmsftngxa08.phx.gbl microsoft.public.dotnet.framework.compactframework:42767
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Here you are adding a new row to your Table and then deleting it.
What you need is to get the DataRow you want to delete and delete it.

for (int i=0;i<productsTable.Rows.Count;i++)
{
if (productsTable.Rows[["product"].ToString()
==dataGridProducts[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.CurrentCell.ColumnNumber)+1].ToString())
{
productsTable.Rows.Delete();
productsTable.AcceptChanges();
}
} // for (int i=0;i<dview_UserMarkiert.Table.Count;i++)

Hope this helps.

Mark Johnson, Berlin Germany
(e-mail address removed)



jez said:
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =

dataGridProducts[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cur
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row
that
is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have any primary
keys
in
the table - even though I do. They're specified in a .xsd schema.

thanks, jez
 
J

jez

Alex,

Joe gave me some c# code. Have a look at :
http://groups.google.com/groups?dq=...soft.public.dotnet.framework.compactframework

it seems like the official CF FAQ is a little out of date though.

jez


Alex Yakhnin said:
I "somehow" managed to solve my problem and use
productsTable.Rows.Remove(foundRow);

Glad it worked out for you...
I'm still stuck with the ampersand-problem though.. maybe you've got some
idea about a C# method I could use ?

Could you, please, re-iterate on this "ampersand-problem"?

-Alex
-----Original Message-----
Hey Alex,

I "somehow" managed to solve my problem and use
productsTable.Rows.Remove(foundRow);

I'm still stuck with the ampersand-problem though.. maybe you've got some
idea about a C# method I could use ?

Let me get this straight... You get a DataSet from some
XML. Then you filter rows using DataView, and what do you
bind to the DataGrid? The result from DataView filtering?
Do you have related table in the DataSet?

-Alex

-----Original Message-----
nothing happens..

well it's not bound - bound. I just put the datasource of
the datagrid equal
to one of my datatables. Should I bind it as well ?
What's the difference ?
(bare in mind that I use a dataview as source as I first
filer some rows
out)

message
Assuming that you're trying to delete from the table
that's bound to DataGrid, you could just call:

productsTable.Rows.RemoveAt
(dataGridProducts.CurrentCell.RowNumber);

HTH... Alex

-----Original Message-----
I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] =
listBoxCustomers.SelectedValue;
rowToDelete["productID"] =
dataGridProducts

[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cu
r
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts
[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the
current row that is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I
could use to delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't
have
any primary keys in
the table - even though I do. They're specified in
a .xsd
schema.

thanks, jez


.



.


.
 
I

Ilya Tumanov [MS]

Jez,

Yes, it will work even if you use filtering/sorting as long as you delete
rows from the same DataView DataGrid is bound to.
That would be a table's default DataView if DataGrid's DataSource is set to
a DataTable.
If you using a separate DataView as a DataSource, delete rows from this
view, not from Table's default view.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "jez" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
Subject: Re: Delete DataRow in DataTable ?
Date: Fri, 16 Jan 2004 08:55:30 +0100
Organization: Wanadoo Belgium
Lines: 123
Message-ID: <[email protected]>
References: <[email protected]>
NNTP-Posting-Host: adsl-151-7.wanadoo.be
X-Trace: sinclair.be.wanadoo.com 1074239747 1476771 213.177.151.7 (16 Jan 2004 07:55:47 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Fri, 16 Jan 2004 07:55:47 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Path: cpmsftngxa08.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!newsfeed00.sul.t-online.de!t-online.de!skynet.be!fr.ip.ndsoftware.n
et!nerim.net!feed1.news.be.easynet.net!news.be.wanadoo.com!news.wanadoo.be!n
ot-for-mail
Xref: cpmsftngxa08.phx.gbl microsoft.public.dotnet.framework.compactframework:42788
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Ilya,

that looks like an interesting way to delete a row. Would it still work if I
were to filter out some rows in the dataGrid using RowFilter on a DataView ?
(so that the index of a row in a dataGrid would not correspond with the one
of its datatTable)

"Ilya Tumanov [MS]" said:
Mark,

Here's another way to do it:

productsTable.DefaultView.Delete(dataGridProducts.CurrentRowIndex);

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Mark Johnson" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
References: <[email protected]>
Subject: Re: Delete DataRow in DataTable ?
Date: Fri, 16 Jan 2004 00:01:10 +0100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Lines: 60
Message-ID: <[email protected]>
Organization: Arcor
NNTP-Posting-Date: 16 Jan 2004 00:01:12 MET
NNTP-Posting-Host: 213.23.147.152
X-Trace:
DXC=oBBQ;U7AQC:LL2:TY8[@n6Q5U85hF6f;4jW\KbG]kaM8eDdmR4DE3R<oRGdON<La03jLofn]
?Un[:Y:i@ie^9[=;S3`82`ie0m<
X-Complaints-To: (e-mail address removed)
Path:
cpmsftngxa08.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor-online.net!newsread.arcor-online.net!new
s.arcor.de!not-for-mail
Xref: cpmsftngxa08.phx.gbl microsoft.public.dotnet.framework.compactframework:42767
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Here you are adding a new row to your Table and then deleting it.
What you need is to get the DataRow you want to delete and delete it.

for (int i=0;i<productsTable.Rows.Count;i++)
{
if (productsTable.Rows[["product"].ToString()
==dataGridProducts[dataGridProducts.CurrentCell.RowNumber,
(dataGridProducts.CurrentCell.ColumnNumber)+1].ToString())
{
productsTable.Rows.Delete();
productsTable.AcceptChanges();
}
} // for (int i=0;i<dview_UserMarkiert.Table.Count;i++)

Hope this helps.

Mark Johnson, Berlin Germany
(e-mail address removed)



I tried the following code, without success :

***
DataRow rowToDelete;
rowToDelete = productsTable.NewRow();

rowToDelete["customerID"] = listBoxCustomers.SelectedValue;
rowToDelete["productID"] =



dataGridProducts[dataGridProducts.CurrentCell.RowNumber,dataGridProducts.Cur
rentCell.ColumnNumber].ToString();
rowToDelete["product"] =
dataGridProducts[dataGridProducts.CurrentCell.RowNumber,(dataGridProducts.Cu
rrentCell.ColumnNumber)+1].ToString();

rowToDelete.Delete();
productsTable.AcceptChanges();
***

I don't get an error though.. I just want to delete the current row that
is
selected in a DataGrid.

Am I doing anything wrong ? Is there another way that I could use to
delete
rows ?
I tried to do a Rows.Find(PrimaryKeyValues)
but without success - I get an error saying I don't have any primary keys
in
the table - even though I do. They're specified in a .xsd schema.

thanks, jez
 

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