Option Explicit
Dim strChecked As String
Private Sub Form_Load()
Dim i As Variant, ms_rows As Integer
' Start building the Grid
ms_rows = 20 ' This is the number of rows to print out
With MSFlexGrid1
.Row = 0
.Col = 0
.Rows = ms_rows + 1 'We add 1 to ensure we get all the rows
.Cols = 2
.ColWidth(0) = 250 ' CheckBox column
.ColWidth(1) = 1440 ' Index column
End With
' Now build the Grid
For i = 0 To 20 'm_rows - 1
With MSFlexGrid1
.Row = i: .Col = 0: .CellPictureAlignment = 4 ' Align the checkbox
Set .CellPicture = picUnchecked.Picture ' Set the default checkbox picture to the empty box
.TextMatrix(i, 1) = i
End With
Next
End Sub
Private Sub MSFlexGrid1_Click()
Dim oldx, oldy, cell2text As String, strTextCheck As String
' Check or uncheck the grid checkbox
With MSFlexGrid1
oldx = .Col
oldy = .Row
If MSFlexGrid1.Col = 0 Then
If MSFlexGrid1.CellPicture = picChecked Then
Set MSFlexGrid1.CellPicture = picUnchecked
.Col = .Col + 1 ' I use data that is in column #1, usually an Index or ID #
strTextCheck = .Text
' When you de-select a CheckBox, we need to strip out the #
strChecked = Replace(strChecked, strTextCheck & ",", "")
' Don't forget to strip off the trailing , before passing the string
Debug.Print strChecked
Else
Set MSFlexGrid1.CellPicture = picChecked
.Col = .Col + 1
strTextCheck = .Text
strChecked = strChecked & strTextCheck & ","
Debug.Print strChecked
End If
End If
.Col = oldx
.Row = oldy
End With
End Sub
-
no entiendo tu pregunta.. el codigo ya hace eso que vos decis.. cual es el problema? – gbianchi♦ el 13 dic. 18 a las 19:52
-
puedo seleccionar por separado, lo que quiero es con un botón seleccionar todo. – Luis Colqui el 13 dic. 18 a las 19:54
1 respuesta
Todo lo que estas pidiendo.. esta en tu codigo.. solo hay que entender que hace ese codigo que marca uno. y hacer que marque todos.
Donde el codigo dice que arma la grilla, no esta haciendo otra cosa que "desmarcando" todos los elementos.
Por lo tanto, podemos tomar esa parte:
For i = 0 To 20
...
next
Ahora, adentro, lo unico que tenemos que hacer es cambiar el picture que se usa para que este desmarcado, como marcado
Eso lo esta haciendo para un solo elemento aca:
With MSFlexGrid1
.Row = i
.Col = 0
Set .CellPicture = picUnchecked.Picture
Asi, que aprovechando estas dos cosas, podrias hacer:
For i = 0 To 20
With MSFlexGrid1
.Row = i
.Col = 0
Set .CellPicture = picChecked
end with
next