点击MSFlexGrid数据控件的标题进行数据排序!
2007-04-16 16:47
417 查看
在进行数据库编程的时候,经常会用到MSFlexGrid控件进行数据显示。并且对数据进行排序是必不可少的一个环节。使用Windows系统的用户,会习惯于点击标题进行数据排序。而MSFlexGrid控件本身没有这个功能,笔者经过实践,总结出了点击MSFlexGrid标题进行排序的方法,与大家一起分享。
崔占民
EMAIL:CUIZM@163.COM
先添加MSFlexGrid控件,方法:菜单->工程->部件->Microsoft FlexGrid Control 6.0(后面为版本号),代码如下:
Option Explicit
Private Const STR_SORT_ASC = "△"
Private Const STR_SORT_DESC = "▽"
Private Sub Form_Load()
Dim i As Long
'添加一些试验数据
With MSFlexGrid1
.Rows = 51
.Cols = 5
For i = 0 To 50
.TextMatrix(i, 0) = ("Col" & i)
.TextMatrix(i, 1) = ("Col" & i)
.TextMatrix(i, 2) = ("Col" & i)
.TextMatrix(i, 3) = ("Col" & i)
.TextMatrix(i, 4) = ("Col" & i)
Next
End With
End Sub
'排序函数
Public Sub Sort(sgrd As MSFlexGrid, y As Single)
With sgrd
If y >= .RowPos(0) And y < .RowPos(1) Then
If .Tag <> "" Then
If .Tag <> .Col Then
.TextMatrix(0, .Tag) = Left(.TextMatrix(0, .Tag), Len(.TextMatrix(0, .Tag)) - 1)
End If
End If
If Right(.TextMatrix(0, .Col), 1) = STR_SORT_ASC Then
.Sort = flexSortGenericAscending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_ASC, STR_SORT_DESC)
ElseIf Right(.TextMatrix(0, .Col), 1) = STR_SORT_DESC Then
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_DESC, STR_SORT_ASC)
Else
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = .TextMatrix(0, .Col) & STR_SORT_ASC
End If
.Tag = .Col
End If
End With
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Sort MSFlexGrid1, y
End Sub
代码不多,不过实现的功能还是很方便的~~~~~
崔占民
EMAIL:CUIZM@163.COM
先添加MSFlexGrid控件,方法:菜单->工程->部件->Microsoft FlexGrid Control 6.0(后面为版本号),代码如下:
Option Explicit
Private Const STR_SORT_ASC = "△"
Private Const STR_SORT_DESC = "▽"
Private Sub Form_Load()
Dim i As Long
'添加一些试验数据
With MSFlexGrid1
.Rows = 51
.Cols = 5
For i = 0 To 50
.TextMatrix(i, 0) = ("Col" & i)
.TextMatrix(i, 1) = ("Col" & i)
.TextMatrix(i, 2) = ("Col" & i)
.TextMatrix(i, 3) = ("Col" & i)
.TextMatrix(i, 4) = ("Col" & i)
Next
End With
End Sub
'排序函数
Public Sub Sort(sgrd As MSFlexGrid, y As Single)
With sgrd
If y >= .RowPos(0) And y < .RowPos(1) Then
If .Tag <> "" Then
If .Tag <> .Col Then
.TextMatrix(0, .Tag) = Left(.TextMatrix(0, .Tag), Len(.TextMatrix(0, .Tag)) - 1)
End If
End If
If Right(.TextMatrix(0, .Col), 1) = STR_SORT_ASC Then
.Sort = flexSortGenericAscending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_ASC, STR_SORT_DESC)
ElseIf Right(.TextMatrix(0, .Col), 1) = STR_SORT_DESC Then
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = Replace(.TextMatrix(0, .Col), STR_SORT_DESC, STR_SORT_ASC)
Else
.Sort = flexSortGenericDescending
.TextMatrix(0, .Col) = .TextMatrix(0, .Col) & STR_SORT_ASC
End If
.Tag = .Col
End If
End With
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Sort MSFlexGrid1, y
End Sub
代码不多,不过实现的功能还是很方便的~~~~~
相关文章推荐
- 点击MSFlexGrid数据控件的标题进行数据排序!
- 获取DataGridView绑定BindingSource的数据表,并根据树控件点击进行筛选数据表,下拉控件自定义排序问题初步解决方法,解决了该行属于另一个表的错误提示.
- DataGrid 控件中的数据进行分组、排序和筛选
- ClientDataSet 配合 DBGrid 实现 点击标题进行 排序
- bcb中点击DBGrid标题进行排序
- 点击DataGridView列标题排序后,绑定的DataTable也相应的排序, DataGridView和DataTable数据具有一致性 (新增加了sorted事件的排序方式)
- 点击标题条对数据窗口排序
- 点击delphi中wwDBGrid标题进行排序
- DataGrid点击标题进行排序的JS
- ext的排序,根据点击列表列, 对所有数据进行排序, 而不是仅仅对当前页排序
- datagrid点击标题进行排序
- DataGridView控件点击表列头进行多列关联排序
- JS 点击标题进行排序
- C#:ListView控件如何实现点击列表头进行排序?
- 如何:在 DataGrid 控件中对数据进行分组、排序和筛选
- datagrid点击标题进行排序
- C#:ListView控件如何实现点击列表头进行排序
- C# ListView 点击表头对数据进行排序功能的实现代码
- 在Gridview控件中点击编辑链接,把这一行数据传给编辑界面进行修改
- 在 DataList 或Repeater 控件中对数据进行排序