MSFlexGrid控件属性及使用方法整理

MSFlexGrid控件属性及使用方法整理

=================================================

MSFlexGrid总行数和总列数的定义:

MSFlexGrid1.Rows = 5 '规定表格的总行数为5行

MSFlexGrid1.Cols = 2 '规定表格的总列数为2行

MSFlexGrid某一单元格的文本内容

MSFlexGrid1.TextMatrix(3, 0) =\网站地址\'定义第3行的左边表头文本内容为:“网站地址”

MSFlexGrid1.TextMatrix(3, 2) =\定义第3行第2列的文本内容为:“u3u3.com.cn”

右键选中MSFlexGrid的

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

If Button = vbRightButton Then

MSFlexGrid1.Row = y / MSFlexGrid1.RowHeight(0) - 0.5

MSFlexGrid1.RowSel = MSFlexGrid1.Row

'右键选种当前行---备用u3u3:

'MSFlexGrid1.Col = 0

'MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1

'右键选种当前单元格---备用u3u3:

'MSFlexGrid1.Col = x / MSFlexGrid1.ColWidth(0) - 0.5

'MSFlexGrid1.Col = MSFlexGrid1.Col

'Text1.Text = MSFlexGrid1.Text End If End Sub

MSFlexGrid的单元格被点击时的事件

Private Sub MSFlexGrid1_EnterCell()

MSFlexGrid1.CellBackColor = vbBlue '被点中MSFlexGrid的单元格背景变兰色

MSFlexGrid1.CellForeColor = vbWhite '字体变白色 End Sub

MSFlexGrid的单元格失去光标后的事件

Private Sub MSFlexGrid1_LeaveCell()

MSFlexGrid1.CellBackColor = vbWhite

MSFlexGrid1.CellForeColor = vbBlue End Sub

使MSFlexGrid的单元格内容可编辑

'前提:新建两个text文本框,分别为text1和text1

'====================从这里开始,使单元格可以编辑

Private Sub MSFlexGrid1_EnterCell()

MSFlexGrid1.CellBackColor = vbBlue

MSFlexGrid1.CellForeColor = vbWhite

Text1.Text = MSFlexGrid1.Text

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text) End Sub

Private Sub MSFlexGrid1_LeaveCell()

MSFlexGrid1.CellBackColor = vbWhite

MSFlexGrid1.CellForeColor = vbBlue

End Sub

Private Sub Text1_Change()

MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Text1.Text End Sub

Private Sub Text2_Change() '修改表头

Dim r, c As Integer

r = MSFlexGrid1.Row c = 0

MSFlexGrid1.TextMatrix(r, 0) = Text2.Text End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown

KeyCode = 0

End Select End Sub

'====================使单元格可以编辑,到此结束

MSFlexGrid选中整行和整列

右键点 MSFlexGrid控件,选“属性/样式”,把“合并单元格”选择为:“0 - Never”然后运行程序,就会发现MSFlexGrid可以自由选择整行或整列了!

MSFlexGrid插入行

Private Sub Command1_Click()

If MSFlexGrid1.Rows < 2 Then

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4