Ok, here's the function to simulate checkboxes in a flexgrid:
VB Code:
Public Sub FlexCheck(grid As Control, _
CheckCol As Integer, _
Optional ByVal CheckRow As Variant, _
Optional ByVal CheckValue As Variant)
'init
If IsMissing(CheckRow) Then
If grd.MouseRow <> grd.row Then Exit Sub
CheckRow = grd.row
End If
If IsMissing(CheckValue) Then
If grd.Text = "2" Then Exit Sub
CheckValue = Abs(grd.Text - 1)
End If
With grd
.row = CheckRow
.col = CheckCol
.CellPictureAlignment = flexAlignCenterCenter
.CellAlignment = flexAlignRightCenter
.CellForeColor = .CellBackColor
Set .CellPicture = [COLOR=red]Form1.imgFlexCheck.ListImages(CheckValue + 1).Picture[/COLOR]
.Text = CStr(CheckValue)
End With
End Sub
Also needed:
1. add an image list to a form.
2. Load the images from the attached .Res file to the image list (either at design-time or run-time). FLEXCHK0 should be Image 1, FLEXCHK1 = image 2, FLEXCHK2 = image 3
3. Edit the red line in the code to point to your image list (Should be FormName.ImageListName).
To use:
To Initialize the cell, (I usually do this when I populate the grid row):
VB Code:
FlexCheck Form1.Grid1, 1, Grid1.Row, 0
In the _Click event of the grid:
VB Code:
FlexCheck Form1.Grid1, 1, Me.MouseRow 'this will toggle the checkbox
This function will work with either MSFlexGrid or MSHFlexGrid. If the function is placed in a module, you must pass the 'grd' argument as fully-qualified (as in the example above), if it is in the Form code, you can omit the form qualifier.
To set the image to a grayed checkbox, pass CheckValue as 2. When a checkbox is grayed, clicking on it will not toggle the image, you will have to do that by calling the function and explicity setting the value.