When performing a database programming, the MSFLEXGRID control is often displayed. And sort data is an essential part. Users using a Windows system will be accustomed to clicking on the title for data sorting. The MSFLEXGRID control itself does not have this feature, the author has practically, summed up the method of ordering the MSFLExGrid title, sharing with everyone.
Program source code can be downloaded from your website: http://www.j2soft.cn/
Cui Moven
Email: cuizm@163.com
Add MSFLEXGRID controls, methods: Menu -> Engine -> Parts -> Microsoft FlexGrid Control 6.0 (later is the version number), the code is as follows:
Option expedition
Private const str_sort_asc = "△" private const str_sort_desc = "▽"
Private Sub Form_Load () DIM I as long 'Add some test data 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 Withend Sub
'Sort Functions Public Since (SGRD As MsflexGrid, Y As Single) with sgrd if Y> = .ROWPOS (0) AND Y <.ROWPOS (1) Then if .tag <> "" ".tag <> .col Then .TextMatrix (0, .tag) = left (.textMatrix (0, .tag), Len (.textMatrix (0, .tag)) - 1) end if End ifness (.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 welprivate SUB MSFLEXGRID1_MOU Seup (Button As Integer, Shift As Integer, X as Single, Y As Single) Sort MsflexGrid1, Yend Sub
There are not many code, but the implementation is still very convenient ~~~~~