VB6 - 如何使用 MSFlexGrid 进行多级排序?
我目前有一个 VB6 程序,它主要从 Excel 工作表中读取数据并将其输出到 MSFlexGrid 中。
下面是读入的 Excel 工作表数据。数据填充到表格左半部分的出现列中。
(来源:dipzo.com)
VB6 应用程序请阅读此内容将数据放入多维数组中,然后将其输入到 MSFlexGrid 对象中。 这是执行此操作的代码:
Private Sub GridSort(temp() As String)
fgData.Rows = UBound(temp)
x = 0
Do While x < fgData.Rows
fgData.Row = x
fgData.Col = 0
fgData.Text = temp(x, 0)
fgData.Col = 1
fgData.Text = temp(x, 1)
x = x + 1
Loop
fgData.ColSel = 1
fgData.Sort = flexSortGenericDescending
x = 0
Do While x < fgData.Rows
fgData.Row = x
fgData.Col = 0
temp(x, 0) = fgData.Text
fgData.Col = 1
temp(x, 1) = fgData.Text
x = x + 1
Loop
End Sub
现在这在一定程度上有效。 它按出现和输出对数据进行排序,如下所示:
(来源:dipzo.com)
但是,您可以看到它打乱了第一列的顺序。 我希望数据首先按出现次数排序,但对于出现次数相同的数据,我希望它们按操作排序。 有人知道如何实现这一目标吗?
I currently have a VB6 program that essential reads data from an excel worksheet and spits it out into a MSFlexGrid.
Below is the excel sheet data that is read in. Data is filled into the occurence column for the left half of the table.
(source: dipzo.com)
The VB6 Application then read this data into a multi dimensional array which is then fed into a MSFlexGrid object.
Here is the code to do that:
Private Sub GridSort(temp() As String)
fgData.Rows = UBound(temp)
x = 0
Do While x < fgData.Rows
fgData.Row = x
fgData.Col = 0
fgData.Text = temp(x, 0)
fgData.Col = 1
fgData.Text = temp(x, 1)
x = x + 1
Loop
fgData.ColSel = 1
fgData.Sort = flexSortGenericDescending
x = 0
Do While x < fgData.Rows
fgData.Row = x
fgData.Col = 0
temp(x, 0) = fgData.Text
fgData.Col = 1
temp(x, 1) = fgData.Text
x = x + 1
Loop
End Sub
Now this works to a degree. It sorts the Data by occurences and outputs as so:
(source: dipzo.com)
However, you can see that it messed up the order of the first column. I want the data to be sorted by occurences first, but for data with the same amount of occurences, I want them sorted by operation. Does anybody know a way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSFlexGrid 通过从左到右对列进行排序,并且始终以相同的顺序(降序/升序)对多列中的数据进行排序。 因此,您可以交换“发生”和“操作”列来实现您的目标。
另外,我在这里找到了一组很好的 MSFlexGrid 函数,而且还有一个用于多列的条目排序。 查找条目“对多列进行排序”。 没有测试过,但你可以尝试一下。
The MSFlexGrid is sorting data in multiple columns by sorting the columns from left to right and always in the same order (descending/ascending). So you could swap the columns "occurence" and "operation" to achieve your goal.
Elsewhise, I found here a nice collection of MSFlexGrid functions and there's also one entry for multi-column sorting. Look for the entry "Sorting multiple columns". Didn't test it, but you could give it a try.