Having trouble adding a row to a dataview :(

S

sherifffruitfly

Hi all,

Basic issue. I'm handed a dataview from a function, that's based on a
filtered table. The dataview is then assigned to a combobox for
display. I want to insert a new row into this dataview (the "none
selected" option), and have it at the top of the rowset.

I'm confused about the container-hierarchy of the dataview. Can
someone plz show me how inserting a row at the top of a dataview would
go?

Thanks!

cdj
 
M

Morten Wennevik [C# MVP]

sherifffruitfly said:
Hi all,

Basic issue. I'm handed a dataview from a function, that's based on a
filtered table. The dataview is then assigned to a combobox for
display. I want to insert a new row into this dataview (the "none
selected" option), and have it at the top of the rowset.

I'm confused about the container-hierarchy of the dataview. Can
someone plz show me how inserting a row at the top of a dataview would
go?

Thanks!

cdj

Hi,

I'm afraid you will have to add a DataRowView to the DataView and sort the
data so the "none selected"-row appears topmost. If this acceptable simply
use the DataView.AddNew method.

DataView dv = GetView();
DataRowView drv = dv.AddNew();
drv[0] = "none selected";
drv[1] = 0;
drv.EndEdit();
dv.Sort = "Value ASC";

Column 2 is "Value" containing id numbers so sorting by id will put this row
topmost. Unless you call EndEdit() the row won't get sorted.
 

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