如何在一个Grid表格中的一个单元格加入一个控件?
例如:我想让表格中的第一列的所有单元格是CheckBox.

解决方案 »

  1.   

    用控件数组,调整各控件的.top/left/width/height属性,一般width/height和网格的宽度及高度相同,只须调整.top/left
      

  2.   

    http://expert.csdn.net/Expert/topic/1908/1908208.xml?temp=.8142816
      

  3.   

    比如有一个checkBox1数组,以下例示第一行加入checkbox1
       dim i as integer
       For i = 0 To DataGrid1.Columns.Count - 1
          checkbox1(i).top = DataGrid1.Columns(i).Top
          checkbox1(i).left = DataGrid1.Columns(i).left
       Next i
      

  4.   

    一个更简单,开销更小的方法:
    使用msflexgrid控件(字体可以逐单元格设置),将第一列的字体(用cellfont属性)设置为Wingdings。
    "select iif(field1,asc(254),asc(111)) as row1, field2, field3 ... from ..."
    以上假定field1字段是Boolean数据类型。
    这样,true值显示为一个打了勾的方框,false显示为空方框。
    你可以通过rowcolchange事件判断用户点击的是否第一列。如是,将当前记录的field1改写:
    dim n as long
    if msflexgrid1.col=0 and flag then
    n = data1.recordset.absoluteposition
    data1.recordset!field1 = not data1.recordset!field1
    flag = false '模块级变量
    data1.recordset.requery
    data1.recordset.absoluteposition = n
    end if
    flag = true
      

  5.   

    将下面代码粘到窗体中即可(flxGrid, imagelist)
    利用粘图片的方法,很好使!!若还有问题可EMail: [email protected] Sub grdList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    '点击第0列的复选框决定是否为明细级记录
    Dim lCrow  As Long, lCcol As Long
        
        With grdList
                lCrow = HitRow(grdList, Y)
                lCcol = HitCol(grdList, X)
                
                If lCcol = -1 Then
                    .Col = 0
                    Set .CellPicture = imglPic.ListImages.Item("check2").Picture
                End If
        End With
    End Sub
    '返回当前给定y坐标在MSFlexGrid中的第几行
    Public Function HitRow(grd As MSFlexGrid, ByVal Y As Single) As Long
        Dim lRow As Single
        
        With grd
        For lRow = .TopRow To .Rows - 1
            If Y > .RowPos(lRow) And Y <= .RowPos(lRow) + .RowHeight(lRow) Then
                HitRow = lRow
                Exit Function
            End If
        Next lRow
        End With
        HitRow = -1
    End Function
    '返回当前给定x坐标在MSFlexGrid中的第几列
    Public Function HitCol(grd As MSFlexGrid, ByVal X As Single) As Long
        Dim lCol As Single
        
        With grd
        If X <= .ColPos(.leftCol) Then
            HitCol = -1
            Exit Function
        End If
        
        For lCol = .leftCol To .Cols - 1
            If X > .ColPos(lCol) And X <= .ColPos(lCol) + .ColWidth(lCol) Then
                HitCol = lCol
                Exit Function
            End If
        Next lCol
        HitCol = -2
        End With
    End Function
      

  6.   

    '返回当前给定x坐标在MSFlexGrid中的第几列.MouseCol
      

  7.   

    "imglPic"是什么呀?
    “Set .CellPicture = imglPic.ListImages.Item("check2").Picture”我执行这一句出错。
      

  8.   

    imglpic是imagelist定义的对象,在使用前先定义!