Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Display Datagrid with checkboxes

Last post 05-29-2008 3:34 PM by Benniit. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-17-2008 9:17 AM

    • Benniit
    • Not Ranked
    • Joined on 12-06-2006
    • New Member
    • Points 15

    Display Datagrid with checkboxes

    Please I've been struggling to use a datagrid control to display records with check Boxes which I could not, and has been come a headache for me.

    Can any kind person/Guru help me solve this problem. For God's sake. I've been going from site to site, but helplessly unattended to. 

    Please help me solve it.

     

    Thank you, and hope 2 hear from you soon

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-22-2008 2:44 PM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Member
    • Points 445

    Re: Display Datagrid with checkboxes

    Hey,

     

    I nicked this from http://www.codeguru.com/vb/gen/vb_database/datagrid/article.php/c7587/

    There is example code there also.

     

    Quick example
    Need a checkbox called cb ; index = 0 ; width & height = 190
    datagrid = Grid


    Private Sub Form_Load()
      'My fourth column is the check box column
      SetCheckboxes 3, cb
    End Sub

    Private Sub SetCheckboxes(ColNdx As Long, ByRef ChkboxArray As Object)
        bInSetCheckboxes = True
    On Error GoTo ErrorExit
        Dim i
        Dim obj As Object
        Set obj = Grid
           
        Dim OffsetX As Long, OffsetY As Long
        If Not ChkboxArray(0).Container Is Grid.Container Then
            CalcContainerOffset obj, OffsetX, OffsetY
        End If
       
        On Error Resume Next
       
        With Grid
            If (ChkboxArray.UBound <> .VisibleRows) Then
                For i = ChkboxArray.UBound + 1 To .VisibleRows - 1
                    Load ChkboxArray(i)
                    ChkboxArray(i).Width = 190
                    ChkboxArray(i).Height = 190
                Next
                For i = .VisibleRows To ChkboxArray.UBound
                    Unload ChkboxArray(i)
                Next
            End If
       
            OffsetX = OffsetX + (.Columns(ColNdx).Width - ChkboxArray(0).Width) / 2
            OffsetY = OffsetY + 10 ''(.RowHeight - ChkboxArray(0).Height) / 2

            .Columns(ColNdx).Alignment = dbgCenter
            .Columns(ColNdx).Locked = True
           
            '
            If .LeftCol <= ColNdx Then
                For i = 0 To .VisibleRows - 1
                    ChkboxArray(i).Value = Abs(.Columns(ColNdx).CellValue(.RowBookmark(i)))
                    ChkboxArray(i).Top = .Top + .RowTop(i) + OffsetY
                    ChkboxArray(i).Left = .Left + .Columns(ColNdx).Left + OffsetX
                    ChkboxArray(i).Visible = True
                    ChkboxArray(i).ZOrder
                Next
            Else
                i = 0
            End If
           
            For i = i To ChkboxArray.UBound
                ChkboxArray(i).Visible = False
            Next
           
        End With
      
    ExitPoint:
        bInSetCheckboxes = False
        Exit Sub

    ErrorExit:
        Resume ExitPoint
    End Sub

     


    Public Function CalcContainerOffset( _
            obj As Object, _
            ByRef OffsetX As Long, _
            ByRef OffsetY As Long _
        )
       
       
        Do While Not (obj.Container Is obj.Parent)
            Set obj = obj.Container
            If Not (obj Is Nothing) Then
                OffsetX = OffsetX + obj.Left
                OffsetY = OffsetY + obj.Top
               
                '' The offsets for borders below are not exact for frames,
                '' this positioning algorithm works perfectly at any depth
                '' of nested pictureboxes, with any combination of borders
                '' and/or 3D at any levels.
                ''
                '' Using a frame with borders and/or 3d throws a visible skew
                '' on the positions but this should be fixable with some trial
                '' and error -- the skew is no more than 2 px. per frame.
                ''
                '' Other containers may be subject to different metrics.
                ''
                If obj.BorderStyle = 1 Then '' fixed single
                    If obj.Appearance = 1 Then '' 3d
                        OffsetX = OffsetX + 30
                        OffsetY = OffsetY + 30
                    Else
                        OffsetX = OffsetX + 15
                        OffsetY = OffsetY + 15
                    End If
                End If
            End If
            If (TypeOf obj Is Form) Or (TypeOf obj Is MDIForm) Then Exit Do
        Loop


    End Function


     

     

     

     

    • Post Points: 10
  • 05-29-2008 3:34 PM In reply to

    • Benniit
    • Not Ranked
    • Joined on 12-06-2006
    • New Member
    • Points 15

    Re: Display Datagrid with checkboxes

    Hey Guru, Sorry for the delay in reply. Thanks a lot for attending to me. It works fine! may the good Lord bless u. Ben
    • Post Points: 5
Page 1 of 1 (3 items)