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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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?

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

732 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