按照数字排序

gare1000 2005-07-16 02:15:04
使用ComponentOne Studio for .NET 公司的C1FlexGrid绑定DataView ,怎样对字符型的数字按照数字进行排序而不是按照字符排序。例如对1,4,5,11,12,2,3 进行排序的结果是 1,2,3,4,5,11,12 而不是1,11,12,2,3,4,5
...全文
656 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
gare1000 2006-04-18
  • 打赏
  • 举报
回复
不要消沉
jacobzhang 2005-10-08
  • 打赏
  • 举报
回复
gare1000 2005-07-31
  • 打赏
  • 举报
回复
up
hzybc 2005-07-25
  • 打赏
  • 举报
回复
转化为数字
leo_asp 2005-07-24
  • 打赏
  • 举报
回复
学习
gare1000 2005-07-24
  • 打赏
  • 举报
回复
to
gare1000 2005-07-22
  • 打赏
  • 举报
回复
这是Studio for .NET 公司C1FlexGrid控件的Sort方法的说明,有用过的来讨论下
Object.Sort(IComparer compare)
的用法。



Sorts the entire grid or a range of rows based on the contents of one or more columns.

Syntax

Object.Sort(SortFlags flags, int col)

Object.Sort(SortFlags flags, int col1, int col2)

Object.Sort(SortFlags flags, CellRange range)

Object.Sort(int index, int count, IComparer compare)

Object.Sort(IComparer compare)



Parameter
Description

SortFlags flags
One or more values from the SortFlags enumeration that specify the type of sorting (e.g. ascending, descending, case-sensitive, etc).

int col
The column that contains the data to be sorted.

int col1, col2
A range of columns to sort.

CellRange range
A range of cells to sort. If a range is specified, the grid will sort only rows that are contained in the range.

IComparer compare
An object that implements the IComparer interface to compare Row objects. This can be used to provide custom sorting.




Remarks

The Sort method allows you to sort specific columns or cell ranges in ascending or descending order. The flags parameter specifies the sorting order and a few additional options, described below:

Flag
Effect


Ascending
Sort rows in ascending order.

Descending
Sort rows in descending order.

AsDisplayed
Sort comparing the displayed value. If this flag is set, the sorting is based on the formatted string that is displayed to the user. If it is not set, the sorting is based on the underlying data value.

IgnoreCase
Use case-insensitive string comparison.

UseColSort
Use the value stored in the Sort property of each column in the range. This allows you to sort some columns in ascending order and other in descending order.


When you sort multiple columns, the same sorting options are applied to each column, starting from the leftmost column in the range and proceeding to the right.

The grid uses a stable sorting algorithm. This means that the sorting keeps the relative order of records when the sorting key is the same. For example, if you sort a list of files by name, then by extension, file names will still be sorted within each extension group.

To sort multiple columns using a different sorting order for each, you can either call the Sort method multiple times or set each column's Sort property and call the Sort method and include the UseColSort flag in the flags parameter.

To implement custom sorts, you should provide an object that implements the IComparer interface. This simple interface has a single method called Compare that takes two objects as arguments (in this case, they will be Row objects) and returns -1, 0, or +1. For more details, see the documentation for the System.Collections.IComparer interface.

qgqchile 2005-07-22
  • 打赏
  • 举报
回复
排序方法
1 把数字转成STRING 数字.tostring
2 存如一个ARRAYLIST
DIM I AS NEW ARRAYLIST
I.ADD(数字.tostring)
i.sort

这样ARRAYLIST里排列是按照字符而不是数字大小了
AntingZ 2005-07-21
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4121/4121799.xml?temp=.5251123
gare1000 2005-07-21
  • 打赏
  • 举报
回复
我重写了C1FlexGrid控件
重新实现了Compare
可是在运行时却要么报错:
要么 没有反应。
用过C1FlexGrid的发表下高见

Public Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare
Dim row1, row2 As C1.Win.C1FlexGrid.Row
Dim ind1, ind2 As Integer
Dim val1, val2 As Object
row1 = a
row2 = b
ind1 = row1.DataIndex
ind2 = row2.DataIndex

val1 = Me.Item(ind1, Me.Col)
val2 = Me.Item(ind2, Me.Col)

Dim a1, b1 As Decimal
Dim result As Integer
Try
a1 = val1
b1 = val2
If a1 < b1 Then
result = -1
ElseIf a1 = b1 Then
result = 0
Else
result = 1
End If
Catch
result = -1
End Try



Return result

End Function
gare1000 2005-07-21
  • 打赏
  • 举报
回复
AntingZ(夕惕若) ( ) 信誉:131

你给的连接是在后台查询的时候想办法,我需要的是查出来的绑定到ComponentOne Studio for .NET 公司的C1FlexGrid控件后的数据要同时即可以按照字符排许,也要可以按照数字来排。
hamadou 2005-07-20
  • 打赏
  • 举报
回复
再添加一列,把字符型转换成数字型字段,然后以该字段来显示并排序。当然,这样可能会给更新的时候带来麻烦。或者按照一楼的方法,用ID和LEN(ID)两个字段排序。
gare1000 2005-07-20
  • 打赏
  • 举报
回复
up
李洪喜 2005-07-16
  • 打赏
  • 举报
回复
不好解决,
再添加一个 len(fieldname)

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧