请高手帮忙:关于MSFlexGrid与Text控件配合的问题

nofound007 2003-10-16 03:56:26
在MSFlexGrid控件与Text控件配合进行更改MSFlexGrid里的数据时,我的要求是:

当单击(注意:是单击)MSFlexGrid的格子时,可以进行Text编辑,这点我知道怎么做,我的问题是:当编辑了这个text后,我再点另外的格子时,如何立即保存text里的数据到MSFlexGrid?其实如果就是为了做立即保存,我可以在MSFlexGrid1_LeaveCell事件里写代码,可是如果在这个事件里写进这些代码的时候会出来另外的问题,就是当第一次点MSFlexGrid格子时,相应列里的第一格被填充为空格了!
不知道有没有高手写过关于这两个控件配合时的一些代码,请帮忙解决一下,有没有比较好的办法!!

当然如果把单击事件放到双击事件里,是没有什么太大的问题!!可我就是想在单击事件里完成,所以……

下面是一些代码:
Private Sub MSFlexGrid1_Click()
On Error Resume Next
Dim c As Integer, r As Integer
With MSFlexGrid1
c = .Col: r = .Row
If r = 0 And (c = 0 Or c = 1) Then Exit Sub
txtN.Left = .Left + .ColPos(c) + 50
txtN.Top = .Top + .RowPos(r) + 50
txtN.Width = .ColWidth(c)
txtN.Height = .RowHeight(r) - 20
txtN = .Text
txtN.Visible = True
txtN.SetFocus
End With
End Sub

Private Sub txtN_KeyPress(KeyAscii As Integer)
If KeyAscii = Key_Enter Then
MSFlexGrid1.Text = txtN.Text
txtN.Visible = False
MSFlexGrid1.SetFocus
End If
End Sub

Private Sub txtN_LostFocus()
txtN.Visible = False
End Sub
...全文
55 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcshcn 2003-10-16
  • 打赏
  • 举报
回复
Private Sub Text1_Validate(Cancel As Boolean)
nofound007 2003-10-16
  • 打赏
  • 举报
回复
我想了好多办法,就是没有想到这个办法!!
nofound007 2003-10-16
  • 打赏
  • 举报
回复
高手,厉害,谢谢了!
ljxgeneral 2003-10-16
  • 打赏
  • 举报
回复
同意
射天狼 2003-10-16
  • 打赏
  • 举报
回复
Option Explicit

Dim lngRow As Long, lngCol As Long

Private Sub Form_Load()
Text1.BorderStyle = 0
End Sub

Private Sub MSFlexGrid1_Click()
With MSFlexGrid1
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
Text1.Text = .TextMatrix(.Row, .Col)
Text1.SetFocus
lngRow = .Row
lngCol = .Col
End With
End Sub

Private Sub Text1_LostFocus()
MSFlexGrid1.TextMatrix(lngRow, lngCol) = Text1.Text
End Sub
nofound007 2003-10-16
  • 打赏
  • 举报
回复
补充一点,我不希望全部是按回车保存text里的信息到MSFlexGrid,希望当鼠标点到其实不同的单元格里也可以保存!

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧