找回密码
 立即注册

QQ登录

只需一步,快速开始

miyaminn

论坛元老

48

主题

121

帖子

2万

积分

论坛元老

积分
22182

活字格认证

miyaminn
论坛元老   /  发表于:2015-5-29 16:20  /   查看:10794  /  回复:11
Spread的SortRows方法,如果作为Sort条件的列中有空字符串,则同一个排序条件下,排序结果不同
例如:
测试1        测试2        测试3
1v0                12
0a0        ddd        02
150                152
140                142
130                132
120                122
110                112
1d00                102
90                92
80                82
d70                72
d60                62
e50                52
40d                42
30e                32
d20                22
160                162
170                172
               
我按测试2那列降順排序,则两次的结果不同
第一次:
测试1        测试2        测试3
0a0        ddd        02
1v0                12
d20                22
30e                32
40d                42
e50                52
d60                62
d70                72
80                82
90                92
1d00                102
110                112
120                122
130                132
140                142
150                152
160                162
170                172
               
第二次:
测试1        测试2        测试3
0a0        ddd        02
150                152
140                142
130                132
120                122
110                112
1d00                102
90                92
80                82
d70                72
d60                62
e50                52
40d                42
30e                32
d20                22
1v0                12
160                162
170                172
               
请问有什么办法解决吗?
谢谢!

11 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-5-29 17:56:00
沙发
回复 1楼miyaminn的帖子

感谢对该问题的描述。
根据你的提示,你使用了SortRows方法对列进行排序。
为了帮助你解决问题,首先要重现问题,因此我需要了解你的SortRows的代码以及详细的操作步骤。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2015-6-1 10:11:00
板凳
回复 2楼Alice的帖子

大致代码如下:
Public Structure SortInfo
        Dim intSortCol As Short 'ソート対象列番号
        Dim intSortOrder As Boolean 'ソート条件(昇順/降順)
End Structure

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim intCol As Short
        Dim udtSortInfo(0) As SortInfo
        udtSortInfo(0) = New SortInfo
       'ソート条件の設定
        With udtSortInfo(0)

           intCol = 1
           .intSortCol = intCol

            '昇順/降順の設定
            If (CheckBox1.Checked = True) Then
                '昇順
                .intSortOrder = True
            Else
                '降順
                .intSortOrder = False
            End If

        End With

        'スプレッドのソート
        Call g_SortSpread(FpSpread1, udtSortInfo, , True)

      
    End Sub

Public Sub g_SortSpread(ByRef spdSpread As FarPoint.Win.Spread.FpSpread, ByRef udtSortInfo() As SortInfo, Optional ByRef lngNoNoCol As Integer = 0, Optional ByVal needSortEmpty As Boolean = False)

      
        Dim intNum As Short 'ソート条件設定用No
        Dim spdRow As Integer
        Dim spdSortInfo() As FarPoint.Win.Spread.SortInfo = Nothing

        With spdSpread
            .SuspendLayout()

           'ソート範囲の指定
            spdRow = 0
         

            'ソート条件の設定
            intNum = 0
            For intCounter = LBound(udtSortInfo) To UBound(udtSortInfo)
                ReDim Preserve spdSortInfo(intNum)
                If needSortEmpty Then
                    spdSortInfo(intNum) = New FarPoint.Win.Spread.SortInfo(udtSortInfo(intCounter).intSortCol, udtSortInfo(intCounter).intSortOrder, System.Collections.Comparer.Default)
                Else
                    spdSortInfo(intNum) = New FarPoint.Win.Spread.SortInfo(udtSortInfo(intCounter).intSortCol, udtSortInfo(intCounter).intSortOrder)
                End If
                intNum = intNum + 1
            Next intCounter

            'ソート対象の設定(列でソート)
            .Sheets(0).SortRows(spdRow,  .Sheets(0).RowCount, spdSortInfo)

           
            .ResumeLayout()
        End With

    End Sub

然后,spread的celltype都是text型的。数据的话如1楼所示。
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-6-1 14:55:00
地板
回复 3楼miyaminn的帖子

感谢你提供的代码。
你的问题我们收到了,测试后给你反馈。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-6-1 17:24:00
5#
回复 3楼miyaminn的帖子

你好。
对你提供的代码进行测试。
输入初始的三列数据,然后点击button按钮会进行排序。
未出现每次排序结果不一样的状况。
请问,我操作的步骤有什么问题么?
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2015-6-1 17:39:00
6#
回复 5楼Alice的帖子

我自己这里又试了一下,当行数小于18行的时候,不会排序;但当行数大于18行时,就会两次排序不一样
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-6-1 18:26:00
7#
回复 6楼miyaminn的帖子

你好。
请问你的意思是要改变spread的rowcount么?
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2015-6-2 13:37:00
8#
回复 7楼Alice的帖子

我的意思是当RowCount大于某个值的时候就会两次排序不一致
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-6-2 17:36:00
9#
回复 8楼miyaminn的帖子

很抱歉不能重现你的问题。
为了帮助你解决问题,请提供一个可以重现该问题的Demo,然后写清楚你的重现步骤。
我需要重现该问题,才能帮你看看如何解决。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
miyaminn
论坛元老   /  发表于:2015-6-2 20:38:00
10#
回复 9楼Alice的帖子


DEMO.zip (85.89 KB, 下载次数: 541)
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部