Dataview.Sort = ""; Doesn't work or is it me?

  • Thread starter Thread starter Peter S. Guild
  • Start date Start date
P

Peter S. Guild

Hello,

I have a simple routine that uses a dataview to hold information. I need to
sort these columns by section and then by desc. No matter what I do the
dataview will not sort.

What am I doing wrong?

Language is C#
..Net framework is 1.1

The MasterT is a dataview already.

All I get from the output is an un sorted list.

DataView dv = MasterT.Table.DefaultView;

dv.Sort = "section, desc";

for (int j=1; j < dv.Count; j++)
{

temp = dv.Table.Rows[j]["section"].ToString() + "^"
+ dv.Table.Rows[j]["desc"].ToString().Trim() + "^" ;

sw.WriteLine( temp );
} // loop through rows
 
Peter,

When using a dataview, you should not use the Table property to access
the data, as that is the DataTable. The view is providing the sort, not the
table. Because of that, you want to change your code as follows:

temp = dv[j]["section"].ToString() + "^" + dv[j]["desc"].ToString().Trim() +
"^" ;

Hope this helps.
 
Nicholas thank you,

I knew I was doing something simple and wrong.

It does work when I accesst the dataview and not the table.



Nicholas Paldino said:
Peter,

When using a dataview, you should not use the Table property to access
the data, as that is the DataTable. The view is providing the sort, not the
table. Because of that, you want to change your code as follows:

temp = dv[j]["section"].ToString() + "^" + dv[j]["desc"].ToString().Trim() +
"^" ;

Hope this helps.


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

Peter S. Guild said:
Hello,

I have a simple routine that uses a dataview to hold information. I
need
to
sort these columns by section and then by desc. No matter what I do the
dataview will not sort.

What am I doing wrong?

Language is C#
.Net framework is 1.1

The MasterT is a dataview already.

All I get from the output is an un sorted list.

DataView dv = MasterT.Table.DefaultView;

dv.Sort = "section, desc";

for (int j=1; j < dv.Count; j++)
{

temp = dv.Table.Rows[j]["section"].ToString() + "^"
+ dv.Table.Rows[j]["desc"].ToString().Trim() + "^" ;

sw.WriteLine( temp );
} // loop through rows
 
Back
Top