但是其中第3列需要下拉列表框combo
我想实现的功能是:
1、用户在录入数据时是横向录入,从第1列录完数据回车就自动到当前行的第2列,以此类推(该功能已实现)
2、当用户录入完第2列回车后,自动跳到第3列,这时就出现下拉列表框,然后既可以通过鼠标选择列表的内容,也可以通过上下键选择需要的内容,然后选择好后,回车,就自动跳到第4列,以此类推
3、希望该功能可以比较灵活,不容易出错。
我做过了,但是很不好用,不知道大家谁有比较好的办法可以解决我的问题?
8 个解决方案
#1
看看
http://topic.csdn.net/t/20030625/10/1954499.html
我还没看呢,呵呵
http://topic.csdn.net/t/20030625/10/1954499.html
我还没看呢,呵呵
#2
在页面上先托放一个ComboBox
lngrow = Val(MSHF1.row)'行
lngcol = Val(MSHF1.col)'列
If lngrow = 1 Then
MSHF1.Sort = 1
Exit Sub
Else
Combo.Top = MSHF1.CellTop + 390 '焦点在单元格就把COMBOBOX定位到该单元格
Combo.Left = MSHF1.CellLeft + 110
Combo.Height = MSHF1.CellHeight
Combo.Width = MSHF1.CellWidth
Combo.Visible = True
End If
#3
这个代码写在什么事件里?
#4
楼上说的也太简单了吧?好像跟我的要求差很远啊
我要的是当第2列录完回车,这是光标自动跳到第3列,然后下拉列表就自动出现了下拉列表框,下拉列表里的内容都出现,然后通过键盘上的上下键选择内容,选择好后回车,就自动跳到第4列了,而第3列的内容就是我选择的内容
我要的是当第2列录完回车,这是光标自动跳到第3列,然后下拉列表就自动出现了下拉列表框,下拉列表里的内容都出现,然后通过键盘上的上下键选择内容,选择好后回车,就自动跳到第4列了,而第3列的内容就是我选择的内容
#5
2楼的解法是通用方法,你提的问题是要单独编制回车键.
#6
如果明天还没解决那我明天上班给你写全点。。
#7
呵呵,到目前为止还没有解决呢,6楼能否给我解决这个问题呢?谢谢!
#8
Option Explicit
Dim con As New ADODB.Connection
Dim lngrow As Integer
Dim lngcol As Integer
Private Sub Form_Load()
con.ConnectionString = "driver={sql server};server=127.0.0.1;uid=sa;pwd=;database=test"
con.Open
fillmshf1 "select * from kk"
End Sub
Private Sub fillmshf1(ByVal strSql As String)
Dim rs As New Recordset
Dim i As Integer
rs.Open strSql, con, 1, 3
With MSHF1
.Redraw = True
.Rows = rs.RecordCount + 1
.Cols = 5
.Clear
.WordWrap = False
.TextMatrix(0, 0) = "序号"
.TextMatrix(0, 1) = "K1"
.TextMatrix(0, 2) = "K2"
.TextMatrix(0, 3) = "K3"
.TextMatrix(0, 4) = "k4"
For i = 1 To rs.RecordCount
.RowHeight(i) = 300
.TextMatrix(i, 0) = rs.Fields!id
.TextMatrix(i, 1) = rs.Fields!K1
.TextMatrix(i, 2) = rs.Fields!k2
.TextMatrix(i, 3) = rs.Fields!k3
.TextMatrix(i, 4) = rs.Fields!k4
rs.MoveNext
Next
.Redraw = True
End With
rs.Close
Set rs = Nothing
End Sub
Private Sub MSHF1_Click()
lngrow = Val(MSHF1.Row)
lngcol = Val(MSHF1.Col)
If lngrow = 1 Then
Exit Sub
Else
text1.Top = MSHF1.CellTop + 10
text1.Left = MSHF1.CellLeft + 110
text1.Width = MSHF1.CellWidth
text1.Height = MSHF1.CellHeight + 30
text1.Visible = True
text1.Text = MSHF1.TextMatrix(lngrow, lngcol)
text1.SetFocus
text1.SelStart = 0
text1.SelLength = Len(text1.Text)
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MSHF1.Row = lngrow
MSHF1.Col = lngcol + 1
Combo1.Top = MSHF1.CellTop + 10
Combo1.Left = MSHF1.CellLeft + 110
Combo1.Width = MSHF1.CellWidth
text1.Visible = False
Combo1.Visible = True
Combo1.SetFocus
End If
End Sub
#1
看看
http://topic.csdn.net/t/20030625/10/1954499.html
我还没看呢,呵呵
http://topic.csdn.net/t/20030625/10/1954499.html
我还没看呢,呵呵
#2
在页面上先托放一个ComboBox
lngrow = Val(MSHF1.row)'行
lngcol = Val(MSHF1.col)'列
If lngrow = 1 Then
MSHF1.Sort = 1
Exit Sub
Else
Combo.Top = MSHF1.CellTop + 390 '焦点在单元格就把COMBOBOX定位到该单元格
Combo.Left = MSHF1.CellLeft + 110
Combo.Height = MSHF1.CellHeight
Combo.Width = MSHF1.CellWidth
Combo.Visible = True
End If
#3
这个代码写在什么事件里?
#4
楼上说的也太简单了吧?好像跟我的要求差很远啊
我要的是当第2列录完回车,这是光标自动跳到第3列,然后下拉列表就自动出现了下拉列表框,下拉列表里的内容都出现,然后通过键盘上的上下键选择内容,选择好后回车,就自动跳到第4列了,而第3列的内容就是我选择的内容
我要的是当第2列录完回车,这是光标自动跳到第3列,然后下拉列表就自动出现了下拉列表框,下拉列表里的内容都出现,然后通过键盘上的上下键选择内容,选择好后回车,就自动跳到第4列了,而第3列的内容就是我选择的内容
#5
2楼的解法是通用方法,你提的问题是要单独编制回车键.
#6
如果明天还没解决那我明天上班给你写全点。。
#7
呵呵,到目前为止还没有解决呢,6楼能否给我解决这个问题呢?谢谢!
#8
Option Explicit
Dim con As New ADODB.Connection
Dim lngrow As Integer
Dim lngcol As Integer
Private Sub Form_Load()
con.ConnectionString = "driver={sql server};server=127.0.0.1;uid=sa;pwd=;database=test"
con.Open
fillmshf1 "select * from kk"
End Sub
Private Sub fillmshf1(ByVal strSql As String)
Dim rs As New Recordset
Dim i As Integer
rs.Open strSql, con, 1, 3
With MSHF1
.Redraw = True
.Rows = rs.RecordCount + 1
.Cols = 5
.Clear
.WordWrap = False
.TextMatrix(0, 0) = "序号"
.TextMatrix(0, 1) = "K1"
.TextMatrix(0, 2) = "K2"
.TextMatrix(0, 3) = "K3"
.TextMatrix(0, 4) = "k4"
For i = 1 To rs.RecordCount
.RowHeight(i) = 300
.TextMatrix(i, 0) = rs.Fields!id
.TextMatrix(i, 1) = rs.Fields!K1
.TextMatrix(i, 2) = rs.Fields!k2
.TextMatrix(i, 3) = rs.Fields!k3
.TextMatrix(i, 4) = rs.Fields!k4
rs.MoveNext
Next
.Redraw = True
End With
rs.Close
Set rs = Nothing
End Sub
Private Sub MSHF1_Click()
lngrow = Val(MSHF1.Row)
lngcol = Val(MSHF1.Col)
If lngrow = 1 Then
Exit Sub
Else
text1.Top = MSHF1.CellTop + 10
text1.Left = MSHF1.CellLeft + 110
text1.Width = MSHF1.CellWidth
text1.Height = MSHF1.CellHeight + 30
text1.Visible = True
text1.Text = MSHF1.TextMatrix(lngrow, lngcol)
text1.SetFocus
text1.SelStart = 0
text1.SelLength = Len(text1.Text)
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MSHF1.Row = lngrow
MSHF1.Col = lngcol + 1
Combo1.Top = MSHF1.CellTop + 10
Combo1.Left = MSHF1.CellLeft + 110
Combo1.Width = MSHF1.CellWidth
text1.Visible = False
Combo1.Visible = True
Combo1.SetFocus
End If
End Sub