MsFlexgrid实现输入数据的问题
关于如何在MsFlexgrid中输入数据,我在网站上看到了这样的实现代码
我新建了一个名字为gridtext的textbox框
Private Sub Form_Load()
gridtext.Move -10000, -10000, 1, 1
End Sub
Private Sub MSFlexGrid1_EnterCell()
MSFlexGrid1.CellBackColor = vbYellow
MSFlexGrid1.CellForeColor = vbRed
gridtext.Text = MSFlexGrid1.Text
gridtext.SelStart = 0
gridtext.SelLength = Len(gridtext.Text)
End Sub
Private Sub MSFlexGrid1_LeaveCell()
MSFlexGrid1.CellBackColor = vbWhite
MSFlexGrid1.CellForeColor = vbBlue
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MSFlexGrid1.CellBackColor = vbYellow
MSFlexGrid1.CellForeColor = vbRed
gridtext.SetFocus
End Sub
Private Sub gridtext_Change()
MSFlexGrid1.Text = gridtext.Text
End Sub
Private Sub gridtext_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown
KeyCode = 0
End Select
End Sub
确实可以实现在MsFlexgrid中的数据输入。不过我还有几个问题,希望各位高手能赐教
1.如何在输入的时候看到像输入textbox那样的光标?
2.能不能实现用tab键或者上下键来切换要输入的单元格?像excel那样。
3.能不能解释以下gridtext_keydown()过程是什么意思?
[解决办法]
在网上找 msdn 下载 安装 看看 就行了。或买几张D版 msdn 。
[解决办法]
你要光标的?那么就把textbox显示出来
gridtext_keydown看起来是吃掉特殊键了,具体的你debug一下
tab的话你看看flexgrid里面关于key的函数,具体记不得了
[解决办法]
呵呵,我做过类似的开发,当时做了一个MSHFlexGrid控件用来显示和编辑一张表,而且编辑的时候使用了TextBox,CheckBox,ComboBox等控件,处理起来比较烦琐,但是不难。大致实现方法:
Private Sub hflexSpxx_Click()
With hflexSpxx
c = .Col: r = .Row
Select Case c
Case 6 '显示品牌选择框
combPp.Left = .Left + .ColPos(c) + 150
combPp.Top = .Top + .RowPos(r) + 135
combPp.Width = .ColWidth(c)
EscString = .Text
combPp.Text = .Text
combPp.Visible = True
combPp.SetFocus
'MsgBox "品牌框"
Case 9 '显示商品类别选择框
combSplb.Left = .Left + .ColPos(c) + 150
combSplb.Top = .Top + .RowPos(r) + 135
combSplb.Width = .ColWidth(c)
EscString = .Text
combSplb.Text = .Text
combSplb.Visible = True
combSplb.SetFocus
'MsgBox "商品类别框"
Case 10 '显示单位选择框
combDw.Left = .Left + .ColPos(c) + 150
combDw.Top = .Top + .RowPos(r) + 135
combDw.Width = .ColWidth(c)
EscString = .Text
combDw.Text = .Text
combDw.Visible = True
combDw.SetFocus
'MsgBox "单位框"
Case 14 '显示销售方式选择框
combXsfs.Left = .Left + .ColPos(c) + 150
combXsfs.Top = .Top + .RowPos(r) + 135
combXsfs.Width = .ColWidth(c)
EscString = .Text
combXsfs.Text = .Text
combXsfs.Visible = True
combXsfs.SetFocus
'MsgBox "销售方式框"
Case 16 '显示日期设置框
dtpDate.Left = .Left + .ColPos(c) + 150
dtpDate.Top = .Top + .RowPos(r) + 135
dtpDate.Width = .ColWidth(c)
EscString = .Text
dtpDate.Value = .Text
dtpDate.Visible = True
dtpDate.SetFocus
'MsgBox "日期框"
Case 15, 17 '禁止编辑的项目
Case Else '显示输入框
txtInput.Left = .Left + .ColPos(c) + 150
txtInput.Top = .Top + .RowPos(r) + 135
txtInput.Width = .ColWidth(c) - cmdLarge.Width
txtInput.Height = .RowHeight(r)
cmdLarge.Left = txtInput.Left + txtInput.Width - 15
cmdLarge.Top = txtInput.Top
cmdLarge.Visible = True
EscString = .Text
txtInput = .Text
txtInput.SelStart = 0
txtInput.SelLength = Len(txtInput)
txtInput.Visible = True
txtInput.SetFocus
End Select
End With
End Sub
其中hflexSpxx为MSHFlexGrid控件,
txtInput为TextBox,dtpDate为DTPicker,combPp和combSplb、combDw等为ComboBox控件,这些都是输入信息控件
在每一个输入控件的LostFocus()事件中把该控件的Visible = False及Change()事件中写入hflexSpxx.Text=控件名.Text
大致是这样,实现了这些,Tab和上下键就简单了,不知道对你有没有帮助