标题:[开源]MSHFlexGrid程序运行时怎样对单元格进行编辑输入
取消只看楼主
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
 问题点数:0 回复次数:3 
[开源]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
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
得分:0 
不太明白.能说的清楚些吗?或者我的代码有什么问题.我的代码已经实现功能.只是有时格有偏差
2007-11-07 12:26
knight1212
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-8-28
得分:0 
呵呵,好的我看看.
2007-11-07 14:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-184170-1-1.html




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

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