Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox on msflex grid 3

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
Code:
Private Sub MSFlexGrid1_Click()

    Dim I As Integer
    
    With MSFlexGrid1
    
        If .Col = 0 Then
            If .CellPicture = picChecked Then
                Set .CellPicture = picUnchecked
                '.TextMatrix(.Row, 34) = "S"
            Else
                Set .CellPicture = picChecked
                '.TextMatrix(.Row, 34) = "N"
            End If
        End If
        
        'For I = 1 To Me.LN.Caption
        'If .TextMatrix(.Row, 34) <> "S" Then
        '.Row = I
        '.Col = 0
        'Set .CellPicture = picUnchecked
        'End If
        'Next I
        
    End With

End Sub

Actually i use this code to check and uncheck col 0

possible to have the same effect wuthout to use image?
 
What I did a long time ago was - set [tt]CellFontName[/tt] to "Wingdings"
Letter "[tt]þ[/tt]" will give you 'check' symbol, letter "[tt]q[/tt]" will be 'un-checked'.
If you toggle between these two letters, you will get the check/uncheck effect.

UtilGrid_c0jfsz.png


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I've used a similar technique in the past. - but WHY does OP want to avoid the image?
 
For strongm.
Admit i checke tree or more Cell, i need to maintain tha last cheched Cell and set the rest...to nothing
I dont know the way.
Similari optionbutton
 
You can use Wingdings 2 characters if you want option/radio buttons:

W2_lrrlu4.png


If you want to see how this could work, place several labels (all named [tt]Label1[/tt]) on the form as a control array and try this code:

Code:
Option Explicit

Private Sub Form_Load()
Dim i As Integer

For i = Label1.LBound To Label1.UBound
    With Label1(i)
        .FontName = "Wingdings 2"
        .FontSize = 14
        .Caption = Chr(154)
    End With
Next i

Label1(Label1.LBound).Caption = Chr(158)

End Sub

Private Sub Label1_Click(Index As Integer)
Dim i As Integer

For i = Label1.LBound To Label1.UBound
    Label1(i).Caption = Chr(154)
Next i
Label1(Index).Caption = Chr(158)

End Sub

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
>i need to maintain tha last cheched Cell and set the rest...to nothing

OK, so that would typically be an optionbutton rather than a checkbox, as Andy hints above. Code that illustrates this in a flexgrid might be something like:

Code:
[COLOR=blue]Option Explicit

Private Sub Form_Load()
    With MSFlexGrid1
        .ColWidth(0) = 400
        .RowHeightMin = 300
        .Rows = 10
        .Cols = 3
        .Row = 1
        .Col = 0
        .RowSel = .Rows - 1
        .FillStyle = flexFillRepeat
        .CellFontName = "Wingdings 2"
        .CellFontSize = 12
        .CellAlignment = flexAlignCenterCenter
        .Text = Chr(154)
        .FillStyle = flexFillSingle
        .Row = 1
        .Col = 1
    End With
End Sub
 
Private Sub MSFlexGrid1_Click()
    OptionButtons
End Sub

Public Sub OptionButtons()
Dim lp As Long
If MSFlexGrid1.MouseCol = 0 And MSFlexGrid1.MouseRow >= MSFlexGrid1.FixedRows Then
    With MSFlexGrid1
        For lp = .FixedRows To .Rows - 1
            .TextMatrix(lp, 0) = Chr(154)
        Next
        .TextMatrix(.Row, 0) = Chr(158)
    End With
End If
End Sub[/color]

Note the similarity to Andy's code.

 
You don't need to just click on Col 0, you may click on any column to set the 'option':

Code:
Private Sub OptionButtons()
Dim lp As Long

With MSFlexGrid1
    If .MouseRow >= .FixedRows Then
        For lp = .FixedRows To .Rows - 1
            .TextMatrix(lp, 0) = Chr(154)
        Next
        .TextMatrix(.Row, 0) = Chr(158)
    End If
End With

End Sub
[wiggle]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top