对数组列表进行排序 [英] Sort an Array List

查看:81
本文介绍了对数组列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个函数可以将DataTable中字段的行加载到

ArrayList中。

见下:


它还添加一行(例如所有区域)。

我希望这个新行成为第一个记录,所以我添加了一个前面的空格

(例如所有区域)并对ArrayList进行排序。


我刚发现有一些有效记录有一个或多个

空格所以我添加的记录不再是列表中的第一项。


有没有办法为ArrayList创建自定义排序,以便我添加

项目在列表中排名第一?


谢谢


Doug


私有函数dacFillCombo(ByVal stTblNam As String,ByVal stDspFld As

String,_


ByVal stDsplVal As String)As ArrayList


Dim dr As DataRow,al As New ArrayList


尝试


al.Add(stDsplVal)


For每个dr在dsFiles.Tables(stTblNam)。行


al.Add(dr(stDspFld).ToString)


下一页


al.Sort()


返回al


Catch ex As Exception


MsgBox(ex.ToString)


结束尝试


结束功能

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(ByVal stTblNam As String, ByVal stDspFld As
String, _

ByVal stDsplVal As String) As ArrayList

Dim dr As DataRow, al As New ArrayList

Try

al.Add(stDsplVal)

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

al.Add(dr(stDspFld).ToString)

Next

al.Sort()

Return al

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Function

推荐答案

道格,


你想达到什么目的?


看起来可以可以在一个或多个方法/属性中使用数据表或者组合框来完成。

Cor
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

你好Cor,

我想要实现的是拥有一个数组列表(独立于

DataTable)

已排序升序,但有一个项目被添加到列表中(并且确实

不是来自数据表)总是设置为第一项。


数组列表是一个或多个组合框的数据源。


我创建了一个函数来填充填充列表并添加新项目和

将它设置为组合框,因为这发生在一些组合框

和一些桌子。


道格


" Cor Ligthert [MVP]" <无************ @ planet.nl>在消息中写道

news:uu ************** @ TK2MSFTNGP12.phx.gbl ...
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**************@TK2MSFTNGP12.phx.gbl...
Doug,
你想要实现什么?

它可以在数据表或Combobox中的一个或多个方法/属性
中完成。

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



面团,


我什么也看不见arraylist的目的,你可以创建尽可能多的

数据视图,这可能会更容易,所以为什么一个

arraylist?


Cor
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


这篇关于对数组列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆