473,395 Members | 1,761 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,395 software developers and data experts.

display sorted array

if i perform a sort on an array, how do i get the sorted array to be
displayed in a listbox?

thanks

murt

Nov 20 '05 #1
2 1936
* Murt <mu**@itsschmee.com> scripsit:
if i perform a sort on an array, how do i get the sorted array to be
displayed in a listbox?


Sample for binding an arraylist to a listbox:

\\\
Private Sub Test()
FillListBox("F1#Function1|F2#Function3", Me.ListBox1)
End Sub

Private Function FillListBox( _
ByVal Data As String, _
ByVal List As ListBox _
)
Dim s, t() As String, x As Item
Dim al As New ArrayList()
For Each s In Strings.Split(Data, "|")
x = New Item()
t = Strings.Split(s, "#")
x.TheText = t(1)
x.TheValue = t(0)
al.Add(x)
Next s
List.DataSource = al
List.DisplayMember = "TheText"
List.ValueMember = "TheValue"
End Function

Private Class Item
Private m_TheText As String
Private m_TheValue As String

Public Property TheText() As String
Get
Return m_TheText
End Get
Set(ByVal Value As String)
m_TheText = Value
End Set
End Property

Public Property TheValue() As String
Get
Return m_TheValue
End Get
Set(ByVal Value As String)
m_TheValue = Value
End Set
End Property
End Class
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Try the following code snippet.

BTW, a listbox has a sorted property; if your sorting is alphabetical, why
not just get the listbox sort itself. This is also shown below.

To use:

Create a new winforms application, pop a button on the form (called
Button1), pop a listbox on the form (called Listbox1), and paste in the
following.

Regards
Hexathioorthooxalate

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim stringArray() As String = "apple bear aardvark zebra lion".Split("
".ToCharArray())
ListBox1.Items.Clear()
ListBox1.Sorted = False
For i As Integer = 0 To stringArray.Length - 1
ListBox1.Items.Add(stringArray(i))
Next
MsgBox("Press ok to sort")
ListBox1.Sorted = True
End Sub

"Murt" <mu**@itsschmee.com> wrote in message
news:um**************@TK2MSFTNGP09.phx.gbl...
if i perform a sort on an array, how do i get the sorted array to be
displayed in a listbox?

thanks

murt

Nov 20 '05 #3

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

Similar topics

6
by: Michael Hill | last post by:
I have this large array with dates in it. There is a function that sorts it for me. The only problem is that in order for it to get sorted properly I have to sort it AlphaNumerically first using ...
10
by: Ryan Graham | last post by:
I totally bombed this question in an interview so I'm posting my answer here for comments and suggestions... perhaps (god help me) I'm just not that bright, but this works and seems to be fairly...
8
by: Rajesh | last post by:
Question :An element in a sorted list can be found in O(log n) time via binary search. But suppose I rotate the sorted list at some pivot unknown to you beforehand. So for instance, 1 2 3 4 5 might...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
7
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
0
by: neehakale | last post by:
This is the code for the bubble sort Algorithm in c#....pls anybody tel me where should i write the display statment in thos code to see the output of every iteration... static void Main(string...
4
by: Vols | last post by:
I found the following question, and couldn't get the best answer: if you have a sorted and shifted array such like {5,6,7,1,2,3,4}, how to find one element "2"? Thanks. Vol
16
by: Jon Harrop | last post by:
I need a data structure with the following capabilities: 1. Fast access to the smallest element. 2. Fast insertion of a new element. 3. Fast deletion of an existing element. I have been...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.