首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎样使mshflexgrid控件只能单行选择?解决方法

2012-01-18 
怎样使mshflexgrid控件只能单行选择?程序要求用户选中mshflexgrid中的某一行后,可对该行执行某些操作,但通

怎样使mshflexgrid控件只能单行选择?
程序要求用户选中mshflexgrid中的某一行后,可对该行执行某些操作,但通过鼠标可选中mshflexgrid的多行,如果将属性--突出显示改为0,则又只能选中一个网格,不太好看,有无属性设置其只能单行选中?谢谢!

[解决办法]

VB code
Option ExplicitPrivate Sub Form_Load()    Dim strText As String    Dim i As Long, j As Long        strText = "一二三四五六七八九十"    Me.MSHFlexGrid1.Rows = 10    Me.MSHFlexGrid1.Cols = 10    Me.MSHFlexGrid1.FixedCols = 0    Me.MSHFlexGrid1.SelectionMode = flexSelectionByRow    For i = 1 To 10        For j = 1 To 10            Me.MSHFlexGrid1.TextMatrix(i - 1, j - 1) = "第" & Mid(strText, i, 1) & "行第" & Mid(strText, j, 1) & "列"        Next    NextEnd SubPrivate Sub MSHFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)    If Button = 1 Then        Me.MSHFlexGrid1.Row = Me.MSHFlexGrid1.MouseRow        Me.MSHFlexGrid1.Col = 0        Me.MSHFlexGrid1.ColSel = Me.MSHFlexGrid1.Cols - 1    End IfEnd Sub
[解决办法]
无法用属性设置来完成。
但可以用代码搞定:
VB code
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)    If (Button = 1) Then        MSFlexGrid1.Row = MSFlexGrid1.MouseRow        MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1    End IfEnd Sub 

热点排行