sort Dataview

T

tshad

In my program, I have a dataview that I am sorting (dv.sort) and then making
changes to it. I thought I was going to have to re-sort the dataview, but
it seems that it was already re-sorted when I looped through it??? When
does that happen? Does it re-sort itself after each change?

dv.Sort = "primary DESC,formName DESC";

foreach (DataRowView r in dv)
{
PrimaryForms pf = AppSettings.primaryForms.Find(delegate(PrimaryForms
pf1)
{ return pf1.FormName.ToLower() == ((string)r["formName"]).ToLower();});

if (pf != null)
r["primary"] = "True"; <------ Change made here
}

// At this point the DataView seems to be resorted

foreach (DataRowView r in dv)
{
string s;
string s2;
s = (string)r["primary"];
s2 = (string)r["formName"];
}


Thanks,

Tom
 
N

Nicholas Paldino [.NET/C# MVP]

I would guess that it happens at the time of the change. The View is
just that, it's a view on the data. It hooks up to the dataset itself to
determine when it is changed, and if a value is changed that would affect
the rows visibility, or the order in the view, the view will reorder itself
(not the underlying data) appropriately.
 
T

tshad

Nicholas Paldino said:
I would guess that it happens at the time of the change. The View is
just that, it's a view on the data. It hooks up to the dataset itself to
determine when it is changed, and if a value is changed that would affect
the rows visibility, or the order in the view, the view will reorder
itself (not the underlying data) appropriately.

That is probably true. It just seems strange that it would do it after each
change. I would have thought I would have to call dv.Sort again after the
change.

Thanks,

Tom
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
In my program, I have a dataview that I am sorting (dv.sort) and then
making changes to it. I thought I was going to have to re-sort the
dataview, but it seems that it was already re-sorted when I looped
through it??? When does that happen? Does it re-sort itself after each
change?

dv.Sort = "primary DESC,formName DESC";

foreach (DataRowView r in dv)
{
PrimaryForms pf = AppSettings.primaryForms.Find(delegate(PrimaryForms
pf1)
{ return pf1.FormName.ToLower() ==
((string)r["formName"]).ToLower();});

if (pf != null)
r["primary"] = "True"; <------ Change made here
}

// At this point the DataView seems to be resorted

foreach (DataRowView r in dv)
{
string s;
string s2;
s = (string)r["primary"];
s2 = (string)r["formName"];
}


Thanks,

Tom
 

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

Similar Threads


Top