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
Enter your message below
Sign in or Join us (it's free).