如题!!
解决方案 »
- 我做自动更新时遇到程序不能关闭的情况,可否用结束进程的方法关闭?
- 如何对一个2×2的16进制数据的矩阵进行水平和垂直校验??
- 我用WebBrowser控件想实现给网页输值,为什么text的类型的输入框可以实现,但file的类型的输入框不能实现输值呢?我的例子代码如下.
- Persist Security Info=false/or 代表什么意思,在线等!谢谢
- 菜鸟求助
- 十万火急,紧急求助:如何关闭没有mdiform的程序
- vb 怎样在线程中实现对数据库的操作???请帮忙!!!!
- 用VB+SQL做个系统
- 向专家榜的专家,向斑竹提问:如何对最小化,最大化,关闭按钮进行编程(如:不可用、改变功能)?救救我呀!我就差这个问题了!
- 哪里能够找到一个只输入数值型数据的文本控件,并且能够指定小数及整数的位数(不是mask控件)
- 请教热心人:如何在TEXT控件中输入中文?
- MshFlexGrid控件中执行AddItem方法时第一行总为空白,为什么?怎么解决,谢谢.
增加 MsFlexGrid 的编辑功能
概述
MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 实现步骤
1 打开 VB5, 开启一个新的工程。2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..”3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。4 在Form1 的代码中增加声明:Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As Integer5 增加代码到 Grid_KeyPress 过程:Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' Save the position of the grids Row and Col for later:
gRow = Grid1.Row
gCol = Grid1.Col
' Make text box same size as current grid cell:
Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.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 Sub6 增加代码到 Text1_KeyPress 过程:Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub7 增加代码到 Text1_LostFocus 过程: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 = Grid1.Row
tmpCol = Grid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
Grid1.Row = gRow
Grid1.Col = gCol
Grid1.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:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。
巧来方便的实现这编辑功能来扩展MSFLEXGRID的应用(在实际应用中这是很常用的功能)。 你只需按下面的做即可轻松实现编辑MSFLEXGRID控件数据的功能 例在窗体上放一文本框text1,和一MSFLEXGRID控件flexgrid1
加入下例代码
Private Sub Form_Load()
Text1.Move -10000, -10000, 1, 1
End SubPrivate Sub MSFlexGrid1_EnterCell()
MSFlexGrid1.CellBackColor = vbBlue
MSFlexGrid1.CellForeColor = vbWhite
Text1.Text = MSFlexGrid1.Text
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End SubPrivate Sub MSFlexGrid1_LeaveCell()
MSFlexGrid1.CellBackColor = vbWhite
MSFlexGrid1.CellForeColor = vbBlue
End SubPrivate Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Text1.SetFocus
End SubPrivate Sub Text1_Change()
MSFlexGrid1.Text = Text1.Text
End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown
KeyCode = 0
End Select
End Sub
ok,这样一个可编辑的MSFLEXGRID控件就完成了,简单吧!!
让它
grid.textmari(row,col)=grid.textmari(row,col) & chr(keyascii)
象你推荐一个:http://junwhj.myrice.com/
中国人自己开发的
XP风格
有完整的帮助文件
最重要的是:目前免费
下面是例子:
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 5
MSFlexGrid1.AddItem vbTab & "a" & i & vbTab & "b" & i & vbTab & "c" & i & vbTab & "d" & i & vbTab & "e" & i
Next
Text1.Visible = faleEnd SubPrivate Sub MSFlexGrid1_DblClick()
Text1.Visible = True
Text1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.Col)
Text1.Left = MSFlexGrid1.CellLeft
Text1.Top = MSFlexGrid1.CellTop
Text1.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col)
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)End SubPrivate Sub MSFlexGrid1_LeaveCell()
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Text1.Text
End Sub
可以详细解释一下吗?
另,使用EnterCell事件,只要msflexgrid的单元格内容改变都会激活这一事件,而这却不是我们希望的,可以说要让msflexgrid getfocus后才激活,但是,单击msflexgrid并不一定让msflexgrid获得焦点,而单击其它地方也不一定让msflexgrid lostfocus.