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

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
P

Peter S. Guild

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
 

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