Objects:
Form1、Combo1、DataGrid1:
Code:
Dim adoRecordset As ADODB.Recordset
Const dY = 20
Const dX = 10
Const wdX = 8
Const hdY = 10
Private Sub combo1_LostFocus()
Combo1.Visible = False
End Sub
Private Sub DataGrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
Combo1.Move DataGrid1.Left + DataGrid1.Columns(DataGrid1.Col).Left + dX, DataGrid1.Top + DataGrid1.RowTop(DataGrid1.Row) + dY, DataGrid1.Columns(DataGrid1.Col).Width - wdX
End SubPrivate Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Combo1.Move DataGrid1.Left + DataGrid1.Columns(DataGrid1.Col).Left + dX, DataGrid1.Top + DataGrid1.RowTop(DataGrid1.Row) + dY, DataGrid1.Columns(DataGrid1.Col).Width - wdX
Combo1.Visible = True
End Sub
Private Sub DataGrid1_Scroll(Cancel As Integer)
Combo1.Visible = False
End Sub
Private Sub Form_Load()
    Set adoRecordset = New ADODB.Recordset '测试用记录集
    For i = 0 To 2
        adoRecordset.Fields.Append "fld" & i, adBoolean
    Next i
    adoRecordset.Open
    Dim b As Boolean
    For i = 0 To 10
        b = Not (b)
        adoRecordset.AddNew Array("fld0", "fld1", "fld2"), Array(b, Not b, b)
    Next i
    Set DataGrid1.DataSource = adoRecordset
    DataGrid1.RowHeight = Combo1.Height
    DataGrid1.AllowRowSizing = False
    DataGrid1.AllowUpdate = False
    Combo1.Visible = False
    Set Combo1.DataSource = adoRecordset
    Dim bFmt1 As New StdDataFormat
    Dim bFmt2 As New StdDataFormat
    Dim bFmt3 As New StdDataFormat
    bFmt1.Type = fmtBoolean
    bFmt1.TrueValue = "√"
    bFmt1.FalseValue = "×"
    Set DataGrid1.Columns(0).DataFormat = bFmt1
    
    bFmt2.Type = fmtBoolean
    bFmt2.TrueValue = "True" '"√"
    bFmt2.FalseValue = "False" '" ×"
    Set DataGrid1.Columns(1).DataFormat = bFmt2
    
    bFmt3.Type = fmtBoolean
    bFmt3.TrueValue = "是" '"√"
    bFmt3.FalseValue = "否" '" ×"
    Set DataGrid1.Columns(2).DataFormat = bFmt3End Sub