Solved

Help with sorting column is DataTable using vb.net

Posted on 2014-02-23
6
2,385 Views
Last Modified: 2014-02-24
Hi,

I'm using the code below to search data in a DataTable, How do I sort the results by SN?

Dim SearchCriteria As String = "Substring(SN, 1,3) IN (" & xyz & " )"

                Dim FilteredDTA As DataTable
                Dim DVA As New DataView(dtsetLinkAOP6A.Tables(0), SearchCriteria, Nothing, DataViewRowState.CurrentRows)
                FilteredDTA = DVA.ToTable
                If FilteredDTA.Rows.Count > 0 Then

                    C1Screen1.Columns(0).Visible = True
                    Me.C1Screen1.DataSource = FilteredDTA.DefaultView.ToTable(True, New String() {"SN", "AGD", "CA"})
                    Me.C1Screen1.Columns("SN").Width = 60
                    Me.C1Screen1.Columns("AGD").Width = 500
                    Me.C1Screen1.Columns("CA").Width = 350
                Else
                    MsgBox("No Records Found")

                End If

Thanks,

Victor
0
Comment
Question by:vcharles
6 Comments
 
LVL 40
ID: 39881766
I di not test, but I would try sorting the DataView before using it to create a table.

DVA.Sort = "SN"
0
 

Author Comment

by:vcharles
ID: 39882456
Hi,

Unfortunately it does not work.

Thanks,

Victor
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39882805
Looking at the documentation for the Sort property, I suspect you need to add either "ASC" or "DESC" in addition to the column name.

e.g.

DVA.Sort = "SN ASC"

Open in new window

0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39882813
Could it be problem related to you trying to sort numeric values in a string column?
0
 

Author Closing Comment

by:vcharles
ID: 39882823
Thank You.
0
 

Author Comment

by:vcharles
ID: 39882832
It worked with DVA.Sort = "SN ASC".

Thanks,

V.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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