http://www.vb-helper.com/HowTo/flexgrd2.zip
Purpose
Search for values in a FlexGrid control and sort it by columns
Method
To search for values, simply loop through the grid looking for the target value. Use the TopRow property to ensure that the row is visible after you find it.
Private Sub Command1_Click()
Dim target_name As String
Dim r As Integer
' Get the name.
target_name = InputBox("Name", "Name", "")
If Len(target_name) = 0 Then Exit Sub
' Search for the name, skipping the column heading row.
target_name = LCase$(target_name)
For r = 1 To MSFlexGrid1.Rows - 1
If LCase$(MSFlexGrid1.TextMatrix(r, 0)) = target_name Then
' We found the target. Select this row.
MSFlexGrid1.Row = r
MSFlexGrid1.RowSel = r
MSFlexGrid1.Col = 0
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
' Make the row visible.
MSFlexGrid1.TopRow = r
Exit Sub
End If
Next r
' We didn't find it.
Beep
End Sub
To sort by columns, use the MouseRow property to see if the user clicked the control's column header. Use MouseCol to see which column was clicked.
Store the selected column number in m_SpotColumn. If this is the same as the previously selected column, toggle the m_SortAscending variable that indicates whether the control is sorting in ascending or descending order. If this is a new column, restore the previous column's heading and select ascending order for the new column.
After you know which column should be sorted and how, select the column and use the Sort property to sort it.
This example uses a numeric sort for street address, zip code, and phone number because they start with numbers. This makes numbers with fewer digits come before numbers with more digits. For example, "8 Main St" < "10 1st". If you sort these alphabetically, "10 1st" < "8 Main St" because "1" < "8".
Private Sub MSFlexGrid1_Click()
Dim txt As String
' See if the user clicked row 0.
If MSFlexGrid1.MouseRow > 0 Then Exit Sub
' See if this is the same column.
If MSFlexGrid1.MouseCol = m_SortColumn Then
' This is the current sort column.
' Change the sort order and the column title.
m_SortAscending = Not m_SortAscending
If m_SortAscending Then
MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
"> " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
Else
MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
"< " & Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
End If
Else
' This is a new sort column.
' Restore the previous sorting column's name.
If m_SortColumn >= 0 Then
MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
Mid$(MSFlexGrid1.TextMatrix(0, m_SortColumn), 3)
End If
' Save the new sort column.
m_SortColumn = MSFlexGrid1.MouseCol
' Sort using the new column.
m_SortAscending = True
MSFlexGrid1.TextMatrix(0, m_SortColumn) = _
"> " & MSFlexGrid1.TextMatrix(0, m_SortColumn)
End If
MSFlexGrid1.Row = 1
MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = m_SortColumn
If m_SortAscending Then
Select Case m_SortColumn
Case 2, 5, 6
MSFlexGrid1.Sort = flexSortNumericAscending
Case Else
MSFlexGrid1.Sort = flexSortStringAscending
End Select
Else
Select Case m_SortColumn
Case 2, 5, 6
MSFlexGrid1.Sort = flexSortNumericDescending
Case Else
MSFlexGrid1.Sort = flexSortStringDescending
End Select
End If
End Sub
Disclaimer
This example program is provided "as is" with no warranty of any kind. It is
intended for demonstration purposes only. In particular, it does no error
handling. You can use the example in any form, but please mention
www.vb-helper.com.
没有合适的资源?快使用搜索试试~ 我知道了~
vb6.0数据库实用程序设计100例源代码.rar
共1294个文件
frm:250个
frx:148个
vbw:112个
5星 · 超过95%的资源 需积分: 50 306 下载量 105 浏览量
2010-10-09
22:47:35
上传
评论 9
收藏 8.6MB RAR 举报
温馨提示
包括100个完整的VB数据库应用程序,可直接编译运行。详尽示例了采用VB进行数据库开发的各种技术细节,内容涉及数据库开发的方方面面,非常棒!
资源推荐
资源详情
资源评论
收起资源包目录
vb6.0数据库实用程序设计100例源代码.rar (1294个子文件)
1 545B
12 109B
basRegistry.bas 27KB
FORMAT1.BAS 24KB
N_PRNPRV.BAS 24KB
basCommonDialog.bas 21KB
Vplib.bas 20KB
Design.bas 14KB
FOTime1.BAS 13KB
Design.bas 11KB
CommonDlg.bas 11KB
CommonDlg.bas 11KB
BinaryMgmt.bas 10KB
basGeneral.bas 6KB
mDB.bas 5KB
FILEPROC.BAS 4KB
Module1.bas 4KB
basMessageBox.bas 4KB
basLockFormSize.bas 4KB
Module1.bas 3KB
modSort.bas 3KB
StringMgmt.bas 2KB
OPENFILE.BAS 2KB
basScreenSize.bas 2KB
modMunir.bas 2KB
zINIMgmt.bas 2KB
main.bas 1KB
Module.bas 1KB
Declares.bas 1KB
Module1.bas 881B
Module1.bas 630B
modMain.bas 404B
modSQL.bas 350B
ProgramFlow.bas 329B
Module1.bas 320B
RECEDIT.BAS 309B
Module1.bas 291B
modPublic.bas 223B
Module1.bas 178B
Module1.bas 111B
Faq2.bas 72B
Global.bas 61B
Clouds.bmp 300KB
TopSecret.bmp 116KB
TopSecret-bg.bmp 116KB
techno_chrome.bmp 98KB
SpaceCruiser.bmp 93KB
techno_chrome_act.bmp 87KB
platin.bmp 67KB
paper.bmp 64KB
paper.bmp 64KB
greate.BMP 42KB
greate-active.BMP 42KB
egg-active.BMP 34KB
egg.BMP 34KB
TopSecret-active.bmp 29KB
a-la-Mac.bmp 20KB
Fillform.bmp 19KB
Fillform.bmp 19KB
Vp_logo.bmp 15KB
techno_chrome_bg.bmp 13KB
image1.bmp 12KB
client.bmp 12KB
titlebar.bmp 12KB
paper-active.bmp 10KB
platin-mask.bmp 8KB
platin-active.bmp 8KB
SpaceCruiser-active.bmp 7KB
paper-active.bmp 6KB
BO3.BMP 6KB
修改.bmp 6KB
greate-mask.BMP 6KB
BO17.BMP 6KB
BO12.BMP 6KB
PO12.BMP 5KB
确定.bmp 5KB
取消.bmp 5KB
添加.bmp 5KB
egg-mask.BMP 5KB
bottom_border.bmp 3KB
bottom_border_bg.bmp 3KB
right_border_bg.bmp 3KB
left_border_bg.bmp 2KB
left_border.bmp 2KB
right_border.bmp 2KB
header.bmp 2KB
header_bg.bmp 2KB
right_top_button.bmp 2KB
right_top_button_bg.bmp 2KB
left_top_button_bg.bmp 2KB
left_top_button.bmp 2KB
categ07.bmp 1KB
categ03.bmp 1KB
categ02.bmp 1KB
categ08.bmp 1KB
categ04.bmp 1KB
categ05.bmp 1KB
categ06.bmp 1KB
categ01.bmp 1KB
btn-close-press.bmp 1KB
共 1294 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
wangyb1
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页