473,804 Members | 3,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sort an Array List

Hi,
I have a function that loads Rows from a field in a DataTable into an
ArrayList.
See below:

It also adds a Row (eg "All Areas").
I wanted this new row to be the first record so I added a preceeding space
(eg " All Areas") and sorted the ArrayList.

I have just found that there are some valid records that have one or more
spaces so my added record is no longer first item in the list.

Is there a way to create a custom sort for the ArrayList so that my added
item is first in the list?

Thanks

Doug

Private Function dacFillCombo(By Val stTblNam As String, ByVal stDspFld As
String, _

ByVal stDsplVal As String) As ArrayList

Dim dr As DataRow, al As New ArrayList

Try

al.Add(stDsplVa l)

For Each dr In dsFiles.Tables( stTblNam).Rows

al.Add(dr(stDsp Fld).ToString)

Next

al.Sort()

Return al

Catch ex As Exception

MsgBox(ex.ToStr ing)

End Try

End Function
Nov 21 '05 #1
18 1771
Doug,

What do you want to achieve?

It looks to something that can be done in one or more methods/properties in
either the datatable or either the Combobox.

Cor
Nov 21 '05 #2
Hi Cor,
What I am trying to achieve is to have an array list (independant of the
DataTable)
sorted ascending but with one item that is added to the list (and it does
not come from the datatable) always set to be the first item.

The array list is the data source for one or more combo boxes.

I created a function to fill the populate the list and add the new item and
set it to the combo box because this happens with a number of combo boxes
and with a number of tables.

Doug

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uu******** ******@TK2MSFTN GP12.phx.gbl...
Doug,

What do you want to achieve?

It looks to something that can be done in one or more methods/properties in either the datatable or either the Combobox.

Cor

Nov 21 '05 #3
Dough,

I don't see the purpose of the arraylist while you can create as much
dataviews as you want which do the job probably much easier, so why an
arraylist?

Cor
Nov 21 '05 #4
How do I add an extra item to a dataview?

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uf******** ******@TK2MSFTN GP12.phx.gbl...
Dough,

I don't see the purpose of the arraylist while you can create as much
dataviews as you want which do the job probably much easier, so why an
arraylist?

Cor

Nov 21 '05 #5
Doug,
How do I add an extra item to a dataview?

If you only want to proof that your arraylist is the solution without
telling why, than don't ask for help.

Probably there are better solutions and therefore it has no reason for
others to spent time for that.

In my opinion should you than just investigate it yourself.

Cor
Nov 21 '05 #6
Cor,
I don't understand your response.

As I explained, I need to add a row item and then sort the data except for
the new item that has to be at the top of the list.

You have not provided me with a solution except to say that a DataView is
better than using an Array List.

If you can explain how I can add an item to a DataView and then do a sort so
that everythin is sorted ascending except for the new item which should be
the top item, then I will appreciate your response.

If you can not provide a solution then that is fine also. (I realise MVPs
can only do so much and it is good that they give up time to help others)

Using an ArrayList allows the new item to be added but I don't know if there
is a way to sort it to get the desired result, just as I don't know if there
is a way to sort a dataview to get that result.

Doug
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
Doug,
How do I add an extra item to a dataview?

If you only want to proof that your arraylist is the solution without
telling why, than don't ask for help.

Probably there are better solutions and therefore it has no reason for
others to spent time for that.

In my opinion should you than just investigate it yourself.

Cor

Nov 21 '05 #7
Doug.

With the few information you gave me, will adding a column in your datatable
probably be the most easy solution. That column can be than the source for
your sortproperty in the dataview.

I hope this helps,

Cor
Nov 21 '05 #8
Thanks Cor,

That does give me something to work on.

I can't add a column to the DataTable as the new item is not in the
datatable but I can add a column to the ArrayList and maybe sort by column
and then by the column that holds the data (assuming that I can sort the
list by 2 columns).

I can not change the datatable/s as they are common sources for many
different selection combo boxes.

Doug
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OU******** *****@TK2MSFTNG P14.phx.gbl...
Doug.

With the few information you gave me, will adding a column in your datatable probably be the most easy solution. That column can be than the source for
your sortproperty in the dataview.

I hope this helps,

Cor

Nov 21 '05 #9
Doug,
I can't add a column to the DataTable as the new item is not in the
datatable


Why not, if you cannot add it to the datatable, than it is probably more
work to add it to an arraylist?

Cor
Nov 21 '05 #10

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

Similar topics

4
5318
by: Brett | last post by:
I have two arrays and i wish to sort the first one numerically, but after sorting, I would like the second array to be in the same matching order as the first array. ie. @l1={3,1,2}; @l2={'a','b','c'}; @l1 = sort {$a <=> $b} (@l1); # sort list @l1 to be {1,2,3}
3
2713
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h> #include<stdlib.h> int main(void) {
9
28841
by: gl | last post by:
How do I take an array or arraylist, and sort it randomly? Like suppose the items in it are (1,2,3,4,5) and I want to get it to be in a random order (2,3,1,4,5). How do you do that? I think it's a call to the array or array lists sort method, but i'm not exactly sure how you do it.
48
4493
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
6
6971
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class DisJunctiveConstraintList : LinkedList<DisjunctiveConstraint>
0
13329
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. Examples of two main problem scenarios are like this: 1) an array containing a first name and another array containing a last name and possibly a third array containing the age of a person; how to sort the
0
8536
Ganon11
by: Ganon11 | last post by:
Earlier, mmccarthy was kind enough to post a short article explaining the Bubble Sort. As she said, this is a relatively slow sorting algorithm. Here, I will attempt to present a slightly faster algorithm called Selection Sort. Imagine you have a list of numbers in random order. You want to sort these numbers in increasing order - that is, every element is smaller than or equal to the next element. It follows that the first element holds...
4
2022
by: artev | last post by:
if I have one simple array 1 4 2 6 for to order the code is: arrayOrdin=arraySimple.sort(); and I have 1
3
10559
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the format was different. Basically you can sort a class having members LastName (string), FirstName (string) and Age (int) according to whether you want to sort by Last Name, First Name or Age, using the .Sort function
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.