Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Select Case DataGrid1.Col
Case 1
Check1.Visible = False
Combo1.Visible = True
Combo1.Width = DataGrid1.Columns(DataGrid1.Col).Width + 50
Combo1.Left = DataGrid1.Left + DataGrid1.Columns(DataGrid1.Col).Left
Combo1.Top = DataGrid1.Top + DataGrid1.Row * (DataGrid1.RowHeight) + (DataGrid1.HeadLines) * 195
Combo1.SetFocus
If DataGrid1.Columns(DataGrid1.Col).Text <> "" Then
Combo1.Text = DataGrid1.Columns(DataGrid1.Col).Text
End If
Case 2
Check1.Visible = True
Check1.Width = DataGrid1.Columns(DataGrid1.Col).Width + 50
Check1.Left = DataGrid1.Left + DataGrid1.Columns(DataGrid1.Col).Left
Check1.Top = DataGrid1.Top + DataGrid1.Row * (DataGrid1.RowHeight) + (DataGrid1.HeadLines) * 195
Check1.SetFocus
Combo1.Visible = False
Case Else
Combo1.Visible = False
Check1.Visible = False
End Select
End Sub
Private Sub Form_Load()
'工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
Dim CN As New ADODB.Connection '定义数据库的连接
Dim Rs As New ADODB.Recordset
CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
On Error Resume Next
With DataGrid1
Combo1.Move .Left + .Columns(.Col).Left, .Top + .RowTop(.Row), .Columns(.Col).Width
End With
End Sub