Sorting ListView Items

Posted on 2006-11-20
Last Modified: 2010-04-23
Hi there

I hava a form that contains a list view that hase 4 columns of string each thier names are wit their indicies:

0- Has Nothing but I added it for allignment thing

1- Variable name

2- Arabic Value

3- English Value

and I want to sort that listview Items acording to Variable name

any one to tell me how to do it

thanks in advance
Question by:mohammadalsayeh
  • 4
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 17978936
You should be able to use a Comparer class to sort the ListView:

Here is an example of implementing a custom Comparer class:

Make a ListView control sort using the column you click in VB .NET


Author Comment

ID: 17979850
but I want to sort it before I display it on a listview

LVL 96

Expert Comment

by:Bob Learned
ID: 17979922
What are you displaying?  Where are you getting the data to display in the ListView?

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

LVL 15

Expert Comment

ID: 17984844
if you are querying it from a database then you can add "ORDER BY Variable_name" to the end of the query to sort it.

Author Comment

ID: 17985513
I`m getting it from an xml file by Dataset

I did put it in a default view and sorted it by using the sort property but it didn`t work

LVL 96

Expert Comment

by:Bob Learned
ID: 17986368
How did you try to sort the DefaultView, and why didn't it work?

   table.DefaultView.Sort = "Variable DESC"

LVL 96

Accepted Solution

Bob Learned earned 250 total points
ID: 17986374
After applying a sort to the DefaultView, where you trying to get the values from the table or the DataView:

   For Each row As DataRow In table.Rows


   For Each row As DataRowView in table.DefaultView


Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now