在线问题:实现MsFlexGid排序的功能

JeffreyGUOTJ 2003-09-16 02:24:42
问题:我需要在MsFlexGid的表头列出u多个字段,同时要求点击表头时,按照id进行升序和降序的排列。请问怎么实现,最好是给出思路然后能提示性的给我代码。谢谢大家!
...全文
107 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
flc 2003-09-17
  • 打赏
  • 举报
回复
学习
up
cnhgj 2003-09-17
  • 打赏
  • 举报
回复
dim Msort as integer
Private Sub msf1_Click(Index As Integer)
If Msort = 1 Then
.Sort = 2
Msort = 0
Else
.Sort = 1
Msort = 1
End If
end sub
MSSQL 2003-09-16
  • 打赏
  • 举报
回复
msf_mousemove事件中判断是否是表头
如果是的话再在click中去执行以下代码。
MSF.Col = 1
MSF.Sort = 1

northwolves 2003-09-16
  • 打赏
  • 举报
回复
建议用listview
betagain 2003-09-16
  • 打赏
  • 举报
回复
下面是正确答案,祝你顺利
dim Haha as boolean

Private Sub MSFlexGrid1_Click()
if msflexgrid1.mouserow=0 then
if haha=false then
with msflexgrid1
.Col=.mousecol
.sort=1 'sort的值又好几个,建议查一下msdn
end with
haha=true
else
with msflexgrid1
.Col=.mousecol
.sort=2
end with
haha=false
end if
End Sub
xzp1030 2003-09-16
  • 打赏
  • 举报
回复
Private Sub MSFlexGrid1_Click()

Me.MSFlexGrid1.Col = me.msflexgrid1.colsel
Me.MSFlexGrid1.Sort = 1

End Sub
yijiansong 2003-09-16
  • 打赏
  • 举报
回复
UP
lxcc 2003-09-16
  • 打赏
  • 举报
回复
MSHFlexGrid1.Sort [=value]
value值如下
Constant Value Description
flexSortNone 0 None. No sorting is performed.
flexSortGenericAscending 1 Generic Ascending. An ascending sort, which estimates whether text is string or number, is performed.
flexSortGenericDescending 2 Generic Descending. A descending sort, which estimates whether text is string or number, is performed.
flexSortNumericAscending 3 Numeric Ascending. An ascending sort, which converts strings to numbers, is performed.
flexSortNumericDescending 4 Numeric Descending. A descending sort, which converts strings to numbers, is performed.
flexSortStringNoCaseAsending 5 String Ascending. An ascending sort using case-insensitive string comparison is performed.
flexSortNoCaseDescending 6 String Descending. A descending sort using case-insensitive string comparison is performed.
flexSortStringAscending 7 String Ascending. An ascending sort using case-sensitive string comparison is performed.
flexSortStringDescending 8 String Descending. A descending sort using case-sensitive string comparison is performed.
flexSortCustom 9 Custom. This uses the Compare event to compare rows.


The Sort property always sorts entire rows. To specify the range to be sorted, set the Row and RowSel properties. If Row and RowSel are the same, the MSHFlexGrid will sort all non-fixed rows.

The keys used for sorting are determined by the Col and ColSel properties. Sorting is always done in a left-to-right direction. For example, if Col =3 and ColSel =1, the sort is done according to the contents of columns 1, then 2, then 3.

排序属性总是grid内的全部行进行排序,设置Row和RowSel属性可以对指定的范围进行排序。如果Row和RowSel相同,则grid对全部非固定列排序。
排序所用的关键字是由COl和Colsel属性来决定的。同时是按照从左向右的方向顺序来排序的,比如col=3,colsel=1,排序是按照第1、2、3列的顺序来完成的。

慢慢研究一下吧!
jary12581 2003-09-16
  • 打赏
  • 举报
回复
给你一段代码仔细研究,和你提的问题基本相同,主要是order by 字句在select查询语句中的使用:
Dim gridrow As Integer
gridrow = 0
Dim s As String
Dim rs As Recordset
If Increating_Decline = True Then
If singleorall = False Then
s = "select name," & cs & ",riqi" & " " & "from jjqk where address='" & address & "'" & "order by" & " " & cs
ElseIf singleorall = True Then
s = "select name," & cs & ",riqi" & " " & "from jjqk" & " " & "order by" & " " & cs
End If
ElseIf Increating_Decline = False Then
If singleorall = False Then
s = "select name," & cs & ",riqi" & " " & "from jjqk where address='" & address & "'" & "order by" & " " & cs & " " & "desc"
ElseIf singleorall = True Then
s = "select name," & cs & ",riqi" & " " & "from jjqk" & " " & "order by" & " " & cs & " " & "desc"
End If
End If
Set rs = New Recordset
rs.Open s, myconn, adOpenKeyset, adLockOptimistic
If Not rs.BOF Then
rs.MoveFirst
Do Until rs.EOF
If Trim(rs.Fields(1).Value) <> "" Then
If CDbl(Trim(rs.Fields(1).Value)) >= CDbl(Trim(Text3.Text)) And CDbl(Trim(rs.Fields(1).Value)) <= CDbl(Trim(Text4.Text)) Then
gridrow = gridrow + 1
Me.MSFlexGrid1.Row = gridrow
Me.MSFlexGrid1.Col = 0
Me.MSFlexGrid1.Text = Trim(rs.Fields(0).Value)
Me.MSFlexGrid1.Col = 1
Me.MSFlexGrid1.Text = Trim(rs.Fields(2).Value)
Me.MSFlexGrid1.Col = 2
Me.MSFlexGrid1.Text = rs.Fields(1).Value
End If
End If
rs.MoveNext
Loop
Else
MsgBox "记录集不存在!", vbExclamation, "提示"
End If
JeffreyGUOTJ 2003-09-16
  • 打赏
  • 举报
回复
我提的问题 你别晕倒哦~~
(取当前表头第一个字符的ACSII码) 不太明白
能否详细地说~~~
此外 我查了一下msdn 是不是需要 Sort、TextMatrix 属性 (MSHFlexGrid)
能否给个示例: 谢谢
lxcc 2003-09-16
  • 打赏
  • 举报
回复
rs.Sort = "字段1 ASC" '升序
或者
rs.Sort = "字段1 DESC" '降序

然后重新绑定
set MsFlexGrid1.datasource=rs

不过最好用listview,排序比较方便
aalei 2003-09-16
  • 打赏
  • 举报
回复
当你点击某表头时,让记录集里的记录按指定的顺序排序(取当前表头第一个字符的ACSII码),然后刷新一下就可以了

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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