471,350 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Having trouble adding a row to a dataview :(

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
Sep 12 '08 #1
1 865

"sherifffruitfly" wrote:
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.
--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 15 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Eric Petruzzelli | last post: by
1 post views Thread by Mel Weaver | last post: by
1 post views Thread by Vee Kay | last post: by
16 posts views Thread by scorpion53061 | last post: by

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.