今天开博-也是开始学习编程VB——MSFLEXGRID控件中实现单元格的编辑

为了不让自己下岗,开始学习编程先从VB开始,然后到VB.NET,在这里收集一些编程的源程序和编程技巧,为了自己方便查看,也为了不想下岗而学习的编程的同志们!

今天先发一个在MSFLEXGRID控件中实现单元格的编辑

[@more@]

Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As Integer

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
' Save the position of the grids Row and Col for later:
gRow = MSFlexGrid1.Row
gCol = MSFlexGrid1.Col
' Make text box same size as current grid cell:
Text1.Width = MSFlexGrid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = MSFlexGrid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = MSFlexGrid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 ' 把 Text1 放到最前面!
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
MSFlexGrid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub

Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
' Save current settings of Grid Row and col. This is needed only if
' the focus is set somewhere else in the Grid.
tmpRow = MSFlexGrid1.Row
tmpCol = MSFlexGrid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
MSFlexGrid1.Row = gRow
MSFlexGrid1.Col = gCol
MSFlexGrid1.Text = Text1.Text ' Transfer text back to grid.
Text1.SelStart = 0 ' Return caret to beginning.
Text1.Visible = False ' Disable text box.
' Return row and Col contents:
MSFlexGrid1.Row = tmpRow
MSFlexGrid1.Col = tmpCol
End Sub

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/97706/viewspace-932536/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/97706/viewspace-932536/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值