Solved

Dataview sort

Posted on 2014-02-06
4
445 Views
Last Modified: 2014-02-06
Hi,

How can i sort my column(dv.Row.Item("Time")) in dataview so the output would be sorted like this (Note where the dots are is just continues numbers going up)

0
1
2
3
4
5
6
7
8
9
..........
43
44
45
HT
46
47
48
49
..........
87
88
89
90
FT

Dim DvTheData As New DataView(scorestable)
        'loop through them all and show them
        For Each dv As DataRowView In DvTheData

	test.Text += dv.Row.Item("Time") & " " & dv.Row.Item("Score") &  "<br>"

        Next

Open in new window

0
Comment
Question by:runnerjp2005
  • 2
4 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 39838525
hi.. you can use sort function like this..
private DataTable getsortedtable(DataTable dt)
 {
    dataview v=dt.defaultview;
    v.sort="columnName DESC";
    dt=v.toTable();
    return dt;
  }

or make a code like this example

DataTable dt = null;
            DataRow dr = null;
 
            DataColumn idCoulumn = null;
            DataColumn nameCoulumn = null;
            DataColumn Description  = null;
            //int i = 0;

            dt = new DataTable();
            id = new DataColumn("ID", Type.GetType("System.Int32"));
            name = new DataColumn("Name", Type.GetType("System.String"));
            Description = new DataColumn("Description",Type.GetType("System.String"));
 
            dt.Columns.Add(id);
            dt.Columns.Add(name);
            dt.Columns.Add(Description);
 
            dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Name"] = "Name1";
            dr["Description"]="Good";
            dt.Rows.Add(dr);
 
            dr = dt.NewRow();
            dr["ID"] = 2;
            dr["Name"] = "Name2";
            dr["Description"] = "VeryGood";
            dt.Rows.Add(dr);
            DataView dv = new DataView(dt);
            dv.Sort = "ID DESC";
0
 

Author Comment

by:runnerjp2005
ID: 39838538
Hi thanks but the issue is between the numbers 45 & 46 is the letters HT - also after 90 is FT
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39838559
You can keep an integer column with 1 to 90, sort it and then insert HT and FT afterwards.
0
 

Author Closing Comment

by:runnerjp2005
ID: 39838601
That would do it!

thanks :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question