---
title: "MSHFlexGrid1使用技巧（二）[如何让MSHFlexGrid实现点击列标题排序] "
author: "cjc"
date: "2005-08-30T00:17:00Z"
tags: []
slug: "mshflexgrid1-mshflexgrid"
draft: false
lastmod: "2005-08-30T00:17:00Z"
id: 299161
url: "https://cjc.iteye.com/blog/299161"
---

Dim mysort As Integer  
Private Sub Form\_Load()  
With MSHFlexGrid1  
.Cols = 4  
.Rows = 20   '20行4列  
For i = 0 To 79  
.TextArray(i) = IIf(i &lt; 4, Chr(i + 65), Format(Int(100 * Rnd), "00"))'随机赋值  
Next  
End With  
mysort = 7' 升序  
End Sub  
Private Sub MSHFlexGrid1\_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)  
mysort = 15 - mysort '升序降序转换  
With MSHFlexGrid1  
If Button = 1 And .MouseRow = 0 Then '点击左键,第1 行  
.Col = .MouseCol '选择排序列  
.ColSel = 1  
.Sort = mysort '排序方式  
End If  
End With  
End Sub