请mccad进来一下,急盼指导?
在一个窗体中我引入了mshflexgrid控件,由于mshflexgrid控件不能修改单元格中的内容,于是在窗体中加入textbox,将textbox中的值放到mshflexgrid中,程序如下:Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
If MSHFlexGrid1.RowMSHFlexGrid1.Rows - 1 Then
' 移动文本框至当前单元格
TextBox1.top = MSHFlexGrid1.CellTop + MSHFlexGrid1.top
TextBox1.Left = MSHFlexGrid1.CellLeft + MSHFlexGrid1.Left
' 保存当前单元格行和列的位置
gRow = MSHFlexGrid1.Row
gCol = MSHFlexGrid1.Col
' 设置文本框与当前单元格相同大小
TextBox1.Width = MSHFlexGrid1.CellWidth
TextBox1.Height = MSHFlexGrid1.CellHeight
'最后一列不能填如数据
If MSHFlexGrid1.RowMSHFlexGrid1.Rows - 1 Then
TextBox1.Text = MSHFlexGrid1.Text
' 显示文本框
TextBox1.Visible = True
TextBox1.ZOrder 0 ' 把 Text1 放到最前面!
TextBox1.SetFocus
'重新定位事件至文本框
If KeyAsciiASC_ENTER And KeyAsciiASC_ESC Then
SendKeys Chr$(KeyAscii)
End If
End If
End If
End Sub
Private Sub TextBox1_Change()
MSHFlexGrid1.Text = TextBox1.Text
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = ASC_ENTER Then
MSHFlexGrid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub
Private Sub TextBox1_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 = TextBox1.Text ' Transfer text back to grid.
TextBox1.SelStart = 0 ' Return caret to beginning.
TextBox1.Visible = False ' Disable text box.
' Return row and Col contents:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub
用这种方法基本实现了我要的功能要求,但现在的问题是,mshflexgrid无法聚焦,点击mshflexgrid中的单元格,无法看到光标所在的位置,也就是TextBox1_LostFocus()无效,我该怎么样才能使mshflexgrid聚焦?还有没有别的办法?请赐教,谢谢!
在VBA还是VB里?
VB里有现成的代码,
VBA里不好实现,最好在VB里做一个用户控件,在VBA里调用,或者使用第三方控件
1、是在VBA里做的程序;
2、VBA里不好实现,最好在VB里做一个用户控件,在VBA里调用,或者使用第三方控件?能否说得详细点啊?
我也正学,所有得表格控件都不能修改单元格里的内容吗?只能靠文本框来修改,难道表格只有显示数据的作用?盼着赶紧回答啊! 晕,怎么没有人理了咯? 各位啊,在哪啊?
VBA里用哪个表格控件比较好啊?我想实现数据修改的功能和与数据库里的数据连接的功能。
斑竹啊!
我就是自己做了个控件,在vba里调用,没有办法。 能否拿出来共享一下呢? 也就是用VB做成DLL、OCX等,在VBA里面调用
页:
[1]