sort Dataview

  • Thread starter Thread starter tshad
  • Start date Start date
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
 
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.
 
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
 
Back
Top