Member_2_5230414
asked on
VB.NET Datatable -> how to sort??
Hi guys....
I currently Display what's in my Datatable like this
Is it possible to sort the results by the column "Time".
The time is sorted by numbers ranging from 0-90
but it also has two letter values which are HT and FT (These are football time)
So i need to be abl to sort it from 0-45 ~ HT~ 46-90 ~ FT ... end result would look like:
1
5
16
35
45
HT
HT
46
49
67
89
FT
I currently Display what's in my Datatable like this
Dim DvTheData As New DataView(scorestable)
For Each dv As DataRowView In DvTheData
test.Text += dv.row.Item("Score")
Next
Is it possible to sort the results by the column "Time".
The time is sorted by numbers ranging from 0-90
but it also has two letter values which are HT and FT (These are football time)
So i need to be abl to sort it from 0-45 ~ HT~ 46-90 ~ FT ... end result would look like:
1
5
16
35
45
HT
HT
46
49
67
89
FT
ASKER
Hi.... its stored at sting due to having the Numbers AND Letters in it...
Table is setout like so:
scorestable.Columns.Add("T ime", GetType(String)) being the one i would like to order by
Table is setout like so:
scorestable = new datatable
scorestable.Columns.Add("HomeTeam", GetType(String))
scorestable.Columns.Add("Time", GetType(String))
scorestable.Columns.Add("Score", GetType(String))
scorestable.Columns.Add("Lastgoaltime", GetType(String))
scorestable.Columns.Add("FTtime", GetType(String))
scorestable.Columns.Add("T
>>scorestable.Columns.Add( "Time", GetType(String)) being the one i would like to order by
OK but is the Lastgoaltime going to give the same sort order and wouldn't require further processing ?
OK but is the Lastgoaltime going to give the same sort order and wouldn't require further processing ?
ASKER
no thats just filled if the score is over 0-0 to let me know when a goal has been scored...
everything will be up in order by Time...
here is the site:http://jarrattperkins.com/football/test.aspx
should show you how it would be orderd
everything will be up in order by Time...
here is the site:http://jarrattperkins.com/football/test.aspx
should show you how it would be orderd
OK, no simple way that I see from that info.
If this is in development and you can implement changes I would suggest adding another column to the underlying table as a primary key which increments. Then you can sort on that column as it will sort in the order the records were added (chronologically I assume).
If that isn't a possibility then I would suggest creating a second datatable with the same structure.
Now loop through the source datatable and find the earliest record (eg. 1 in your example) and add a copy into the second datatable, now delete that record in the source datatable. Keep repeating until you have transfered all records into the second datatable with the ordering you desire.
If this is in development and you can implement changes I would suggest adding another column to the underlying table as a primary key which increments. Then you can sort on that column as it will sort in the order the records were added (chronologically I assume).
If that isn't a possibility then I would suggest creating a second datatable with the same structure.
Now loop through the source datatable and find the earliest record (eg. 1 in your example) and add a copy into the second datatable, now delete that record in the source datatable. Keep repeating until you have transfered all records into the second datatable with the ordering you desire.
ASKER
The datatable is created on page load so it will have a bunch of them loaded together with different times and would be mixed up. I suppose I could create four labors 0-45 lable ht-label and 45-90 lable ending on ft label...with doing that how would I pull all ones between 0-45 and order by number
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What are the other columns in the underlying table (eg an incrementing primary key) ?