473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sort FileInfo in ListBox

I'm using the below code to populate a ListBox with file content
information. Sorting the information alpha/numerically is now an
issue. Would someone please let me know the best aproach to take in
doing this.

Thank You

***************************

if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items.Add(files[i].Name);
}
}

Dec 27 '06 #1
4 3412
"Dave" <Ki************@Verizon.Netwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
Would someone please let me know the best aproach to take in
doing this.
http://msdn.microsoft.com/library/de...ortedtopic.asp
Dec 27 '06 #2
Mark,
Thanks for the quick reply, but ".Sorted" isn't an option.

db
Mark Rae wrote:
"Dave" <Ki************@Verizon.Netwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
Would someone please let me know the best aproach to take in
doing this.

http://msdn.microsoft.com/library/de...ortedtopic.asp
Dec 27 '06 #3
Mark,
I think that I should also add that the ListBox is on an ASPX.


Dave wrote:
Mark,
Thanks for the quick reply, but ".Sorted" isn't an option.

db
Mark Rae wrote:
"Dave" <Ki************@Verizon.Netwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
Would someone please let me know the best aproach to take in
doing this.
http://msdn.microsoft.com/library/de...ortedtopic.asp
Dec 27 '06 #4
"Dave" <Ki************@Verizon.Netwrote in message
news:11**********************@n51g2000cwc.googlegr oups.com...
I think that I should also add that the ListBox is on an ASPX.
Hmm - if you'd said that in the first place (or even posted in the aspnet
newsgroup), I'd not have suggested the Sorted property, and you would have
had your answer straightaway...

No matter, here we go:

if (di.Exists)
{
FileInfo[] files = di.GetFiles();
ArrayList lstFiles = new ArrayList();
for (int i = 0; i < files.Length; i++)
{
lstFiles.Add(files[i].Name);
}
lstFiles.Sort();
listBox1.DataSource = lstFiles;
listBox1.DataBind();
}
Dec 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason | last post by:
Here is an odd issue. I am trying to shed some light on why this is causing a problem. I have an ArrayList. I am binding it to a ListBox control with has its Sort property set to True. If the...
0
by: Ray | last post by:
Folks, I have just created a simple procedure that does the following: Determines the width of the columns of a listbox. Places a button of the correct size above each column as the form opens....
4
by: Hrvoje Vrbanc | last post by:
Hello all! I have a small problem: I have an ASP.NET page that displays content of a folder in a DataGrid (more precisely, it displays Name, Lenth and CreationDate of the files). Default sort...
1
by: COHENMARVIN | last post by:
I am trying to display the contents of a directory in a listbox. I manage to get an array of fileInfo objects, and when I print them out they indeed contain several file names. But when I do...
10
by: Amit | last post by:
Hi I'm having a problem using arraylist.sort. I'm using FileInfo.GetFiles() to receive a list of files from a directory. The files have a sequential number to start then theres either an "A"...
4
by: Robin Tucker | last post by:
How do I sort the items in a list box? I am using a class derived from IComparer to sort items on columns in a ListView, but the ListBox doesn't support this kind of facility. The "items" in my...
2
by: Joe Fallon | last post by:
I have 2 listboxes on a Web Form. As I move an item from 1 to the other it shows up at the end of the list. How can I sort the list that just got the new item added to it so it is in alphabetical...
4
by: rn5a | last post by:
Can the items in a ListBox be sorted by the name of the items? The ListBox actually lists all directories & files existing in a directory on the server. Note that all the directories should be...
2
by: Randy | last post by:
I have two listboxes on a form. The first box displays categories while the second box displays the items belonging to the category selected in the first box. Thus, the second box is essentially...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.