---
title: "MSHFlexGrid1使用技巧（一）[如何让MSHFlexGrid只能被选中一行]"
author: "cjc"
date: "2004-09-02T22:35:00Z"
tags: []
slug: "mshflexgrid1-mshflexgrid"
draft: false
lastmod: "2004-09-02T22:35:00Z"
id: 299170
url: "https://cjc.iteye.com/blog/299170"
---

MSHFlexGrid控件点击时可以选中多行，但有时我们需要仅仅选中一行，有一个小技巧：

 

Option Explicit  
Private Sub Form\_Load()  
Dim i As Integer, j As Integer  
With MSHFlexGrid1  
.Rows = 10  
.Cols = 4  
For i = 1 To 9  
.TextMatrix(i, 0) = "第 " & i & " 行"  
For j = 1 To 3  
.TextMatrix(0, j) = "第 " & j & " 列"  
.TextMatrix(i, j) = i & "," & j  
Next  
Next  
.SelectionMode = flexSelectionByRow  
.BackColorSel = vbGreen  
.ForeColorSel = vbRed  
End With  
End Sub  
Private Sub MSHFlexGrid1\_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)  
    With MSHFlexGrid1  
     .Row = .MouseRow  
          .Col = 0  
        .ColSel = .Cols - 1  
    End With  
End Sub