MSHFLEXGRID配合COMBOX lisiview 配合COMBOX 也可以 例子 Option Explicit Dim SubItem As ListItem Dim J As IntegerPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Visible = False End Sub Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Deal Button, X, Y 'MsgBox ListView1.SelectedItem.Index
Dim l As Long, I As Long Dim w As Long Dim h As Long
If ListView1.ListItems.Count = 0 Then Exit Sub
For J = 1 To ListView1.ColumnHeaders.Count w = w + ListView1.ColumnHeaders(J).Width Next 'w = ListView1.Width
'(listview1.listitems.count) 指 listview1 所有的行数 'ListView1.ListItems(1).Height 指 listview1中每一行的高度 h = ListView1.ListItems.Count * ListView1.ListItems(1).Height + 240 If Y > h Then Exit Sub '如果鼠标的Y坐标超过了listview1的数据区域 J = 0 l = X If Button = vbLeftButton And w > 0 Then If l < w - 15 Then Do While l > 0 J = J + 1 l = l - ListView1.ColumnHeaders(J).Width 'J 为找到第几列数 Loop Else Exit Sub End If End If
Text1.Left = 100
If J > 1 Then For I = 1 To J - 1 Text1.Left = Text1.Left + ListView1.ColumnHeaders(I).Width 'text的位置在相应的列
End SubPrivate Sub Text1_Click() 'ListView1.SelectedItem.ListSubItems(ListView1.SelectedItem.Index).Text = Text1 Text1.Visible = False
End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then ListView1.SelectedItem.ListSubItems(J - 1).Text = Text1 Text1.Visible = False End If End SubPrivate Sub Text1_LostFocus() Text1.Visible = False
使用.
vsflexgrid
或者GridEX
lisiview 配合COMBOX 也可以
例子
Option Explicit
Dim SubItem As ListItem
Dim J As IntegerPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Visible = False
End Sub
Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Deal Button, X, Y
'MsgBox ListView1.SelectedItem.Index
Dim l As Long, I As Long
Dim w As Long
Dim h As Long
If ListView1.ListItems.Count = 0 Then Exit Sub
For J = 1 To ListView1.ColumnHeaders.Count
w = w + ListView1.ColumnHeaders(J).Width
Next
'w = ListView1.Width
'(listview1.listitems.count) 指 listview1 所有的行数
'ListView1.ListItems(1).Height 指 listview1中每一行的高度
h = ListView1.ListItems.Count * ListView1.ListItems(1).Height + 240 If Y > h Then Exit Sub '如果鼠标的Y坐标超过了listview1的数据区域 J = 0
l = X
If Button = vbLeftButton And w > 0 Then
If l < w - 15 Then
Do While l > 0
J = J + 1
l = l - ListView1.ColumnHeaders(J).Width 'J 为找到第几列数
Loop
Else
Exit Sub
End If
End If
Text1.Left = 100
If J > 1 Then
For I = 1 To J - 1
Text1.Left = Text1.Left + ListView1.ColumnHeaders(I).Width 'text的位置在相应的列
Next
End If
Text1.Top = ListView1.SelectedItem.Top + 90
Text1.Width = ListView1.ColumnHeaders(J).Width + 10
'Text1.Height = ListView1.ListItems(1).Height
If J = 1 Then
Text1.Text = ListView1.SelectedItem.Text
Else
Text1.Text = ListView1.SelectedItem.ListSubItems(J - 1).Text
End If
Text1.Visible = True
Text1.SetFocus
End Sub
Private Sub Form_Load()
With ListView1
.View = lvwReport
.ColumnHeaders.Add , , "姓名"
.ColumnHeaders.Add , , "性别"
.ColumnHeaders.Add , , "职务"
.ColumnHeaders.Add , , "民族"
.ColumnHeaders.Add , , "国藉"
Set SubItem = .ListItems.Add(, , "张秀雅")
SubItem.SubItems(1) = "女"
SubItem.SubItems(2) = "行政经理"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
Set SubItem = .ListItems.Add(, , "李中明")
SubItem.SubItems(1) = "男"
SubItem.SubItems(2) = "技术部经理"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
Set SubItem = .ListItems.Add(, , "龙莉")
SubItem.SubItems(1) = "女"
SubItem.SubItems(2) = "开发部经理"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
Set SubItem = .ListItems.Add(, , "成主义")
SubItem.SubItems(1) = "男"
SubItem.SubItems(2) = "程序员工"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
Set SubItem = .ListItems.Add(, , "张成江")
SubItem.SubItems(1) = "男"
SubItem.SubItems(2) = "技术员"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
Set SubItem = .ListItems.Add(, , "李不能")
SubItem.SubItems(1) = "男"
SubItem.SubItems(2) = "程序员"
SubItem.SubItems(3) = "汉"
SubItem.SubItems(4) = "中国"
End With
End SubPrivate Sub Text1_Click() 'ListView1.SelectedItem.ListSubItems(ListView1.SelectedItem.Index).Text = Text1
Text1.Visible = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ListView1.SelectedItem.ListSubItems(J - 1).Text = Text1
Text1.Visible = False
End If
End SubPrivate Sub Text1_LostFocus()
Text1.Visible = False
End Sub
====================
免费的学习交流网站,欢迎大家访问!
http://www.j2soft.cn/
加我msn吧
[email protected]
Set Con = New ADODB.Connection
strcon = "driver=mysql odbc 3.51 driver;" & _
"server=" & text3.Text & ";" & _
"database=dtserver;" & _
"port=3306;" & _
"uid=root;" & _
"pwd=waj"
Con.Open strcon
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
strrs = "select * from tab_user where user_user='" & text1.Text & "'"
rs.Open strrs, Con, 3, 2
If rs.RecordCount = 0 Then
MsgBox "用户名不存在!", , "请重试!"
Else
If rs("user_pwd") = text2.Text Then
'成功登陆
'加事件代码
g_ip = text2.Text
Else
MsgBox "密码错误!", , "错误"
End IfEnd If
'Set rs = Nothing
'Set Con = Nothing
Set msflexgrid1.DataSource = rs
Exit Sub
errinfo:
MsgBox Err.Description, , "错误!"
换成datagrid就可以!!不是吧。