| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3778 人关注过本帖, 2 人收藏
标题:[开源]MSHFlexGrid程序运行时怎样对单元格进行编辑输入
只看楼主 加入收藏
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
收藏(2)
 问题点数:0 回复次数:9 
[开源]MSHFlexGrid程序运行时怎样对单元格进行编辑输入

现用的方法是在控件上面加了个TEXT控件.将他的值复制到MS中.但是当程序运行在单元格输入时TEXT的位置与底部格老有偏差.下面是原代码:希望高手指点下.


'*********************编辑使MSHFlexGrid控件可以进行输入
Private Function fgi(ByVal r As Integer, ByVal c As Integer) As Integer
fgi = c + MSHFlexGrid1.Cols * r

End Function


Private Sub MSHFlexGrid1_Click()
fgedit MSHFlexGrid1, TxtEdit, 32
End Sub

Private Sub MSHFlexGrid1_GotFocus()
'MSHFlexGrid1获得焦点
If TxtEdit.Visible = False Then
Exit Sub
End If
'复制数据隐藏文本框
MSHFlexGrid1 = TxtEdit
TxtEdit.Visible = False

End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
'处理MSHFlexGrid1接收按键,进行单元格编辑
fgedit MSHFlexGrid1, TxtEdit, KeyAscii

End Sub
Private Sub fgedit(fg As Control, Edt As Control, KeyAscii As Integer)
Select Case KeyAscii
'根据输入的字符进行相应操作
Case 0 To 32
'空格表示编辑当前文本
Edt = fg
Edt.SelStart = 0
Case Else
' 其他字符代替单元格的文本
Edt = Chr(KeyAscii)
Edt.SelStart = 0
End Select
'定位文本框到对应的单元格位置
Dim X As Integer, Y As Integer
X = 1070 '横向微调
Y = 10 '纵向微调

Edt.Move MSHFlexGrid1.CellLeft + X, MSHFlexGrid1.CellTop - Y, MSHFlexGrid1.CellWidth, MSHFlexGrid1.CellHeight
Edt.Visible = True
Edt.SetFocus

End Sub

Private Sub MSHFlexGrid1_LeaveCell()
'离开MSHFlexGrid1当前单元个前
If TxtEdit.Visible = False Then
Exit Sub
End If
'复制数据并隐藏文本框
MSHFlexGrid1 = TxtEdit
TxtEdit.Visible = False

End Sub

Private Sub TxtEdit_KeyDown(KeyCode As Integer, Shift As Integer)
editkeycode MSHFlexGrid1, TxtEdit, KeyCode, Shift

End Sub

Private Sub TxtEdit_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
End If

End Sub
'处理文本框接受字符
Private Sub editkeycode(fg As Control, Edt As Control, KeyAscii As Integer, Shift As Integer)
Select Case KeyAscii
Case 27
'ESC:隐藏文本框,返回MSHFlexGrid1
Edt.Visible = False
MSHFlexGrid1.SetFocus
Case 13
'返回MSHFlexGrid1
MSHFlexGrid1.SetFocus
Case 38
'向上
MSHFlexGrid1.SetFocus
DoEvents
If MSHFlexGrid1.Row > MSHFlexGrid1.FixedRows Then
MSHFlexGrid1.Row = MSHFlexGrid1.Row - 1
End If
Case 40
'向下
MSHFlexGrid1.SetFocus
DoEvents
If MSHFlexGrid1.Row < MSHFlexGrid1.Rows - 1 Then
MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
End If
End Select

End Sub

搜索更多相关主题的帖子: 单元格 MSHFlexGrid Integer 开源 
2007-11-07 12:01
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
收藏
得分:0 
咋没人回呢?呵呵
2007-11-07 12:09
xlin1033xl
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:160
专家分:129
注 册:2007-6-24
收藏
得分:0 
可以考虑用获取鼠标点击的单元格左上角顶点的坐标(x,y)
Edt.left=x
Edt.top=y

-------------程序*酒*人生
2007-11-07 12:18
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
收藏
得分:0 
不太明白.能说的清楚些吗?或者我的代码有什么问题.我的代码已经实现功能.只是有时格有偏差
2007-11-07 12:26
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 

没时间看你的代码,给你我的代码看看,比较全,让你参考下。


Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
SelectFlag = 1 ‘//窗体上有3 个MSHFlexGrid, 判断选择哪一个MSHFlexGrid
If KeyCode = vbKeyReturn And Not Text1.Visible Then
With MSFlexGrid1
If .ColSel = 1 Then
Call toEditGrid(.Col, .Row)
End If
End With
End If
End Sub

Private Sub Text1_Change()
Select Case SelectFlag
Case 1
MSFlexGrid1.Text = Text1.Text
Case 2
MSFlexGrid2.Text = Text1.Text
Case 3
MSFlexGrid3.Text = Text1.Text
End Select
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
Text1.Visible = False
Select Case SelectFlag
Case 1
MSFlexGrid1.SetFocus
Case 2
MSFlexGrid2.SetFocus
Case 3
MSFlexGrid3.SetFocus
End Select
SendKeys "{up}"
Else
If KeyCode = vbKeyDown Then
Text1.Visible = False
Select Case SelectFlag
Case 1
MSFlexGrid1.SetFocus
Case 2
MSFlexGrid2.SetFocus
Case 3
MSFlexGrid3.SetFocus
End Select
SendKeys "{down}"
End If
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
Text1.Visible = False
Select Case SelectFlag
Case 1
MSFlexGrid1.SetFocus
Case 2
MSFlexGrid2.SetFocus
Case 3
MSFlexGrid3.SetFocus
End Select
End If
If KeyAscii = vbKeyEscape Then
KeyAscii = 0
Select Case SelectFlag
Case 1
MSFlexGrid1.Text = OldText
Text1.Visible = False
MSFlexGrid1.SetFocus
Case 2
MSFlexGrid2.Text = OldText
Text1.Visible = False
MSFlexGrid2.SetFocus
Case 3
MSFlexGrid3.Text = OldText
Text1.Visible = False
MSFlexGrid3.SetFocus
End Select
End If
End Sub

Private Sub Text1_LostFocus()
Text1.Visible = False
End Sub

Private Sub toEditGrid(ByVal C As Integer, ByVal R As Integer)
Select Case SelectFlag
Case 1
With MSFlexGrid1
.Col = C: .Row = R

Text1.Left = .Left + .ColPos(C)
Text1.Top = .Top + .RowPos(R)
If .Appearance = flex3D Then
Text1.Left = Text1.Left + 2 * Screen.TwipsPerPixelX
Text1.Top = Text1.Top + 2 * Screen.TwipsPerPixelY
End If
Text1.Width = .ColWidth(C)
Text1.Height = .RowHeight(R)
Text1.Text = .Text
OldText = .Text
End With
Case 2
With MSFlexGrid2
.Col = C: .Row = R

Text1.Left = .Left + .ColPos(C)
Text1.Top = .Top + .RowPos(R)
If .Appearance = flex3D Then
Text1.Left = Text1.Left + 2 * Screen.TwipsPerPixelX
Text1.Top = Text1.Top + 2 * Screen.TwipsPerPixelY
End If
Text1.Width = .ColWidth(C)
Text1.Height = .RowHeight(R)
Text1.Text = .Text
OldText = .Text
End With
Case 3
With MSFlexGrid3
.Col = C: .Row = R

Text1.Left = .Left + .ColPos(C)
Text1.Top = .Top + .RowPos(R)
If .Appearance = flex3D Then
Text1.Left = Text1.Left + 2 * Screen.TwipsPerPixelX
Text1.Top = Text1.Top + 2 * Screen.TwipsPerPixelY
End If
Text1.Width = .ColWidth(C)
Text1.Height = .RowHeight(R)
Text1.Text = .Text
OldText = .Text
End With
End Select
Text1.Visible = True
Text1.SelStart = Len(Text1.Text)
Text1.SetFocus
End Sub


全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-07 12:49
simpson
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:863
专家分:17
注 册:2006-11-16
收藏
得分:0 
这个代码还可以再压缩,能用就懒得做了

全国最大的 Java专业电子书免费分享[url]http:///in.asp?id=xrmao[/url]
2007-11-07 12:51
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
收藏
得分:0 
呵呵,好的我看看.
2007-11-07 14:22
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 
iH1hujPw.rar (15 KB) [开源]MSHFlexGrid程序运行时怎样对单元格进行编辑输入


看看这个可以不?

2007-11-07 15:44
smartgang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-10
收藏
得分:0 
楼主们真厉害 菜鸟我很佩服
2011-03-10 10:31
快速回复:[开源]MSHFlexGrid程序运行时怎样对单元格进行编辑输入
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.071798 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved