USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Grid/FlexGrid)

Título da Dica:  Checkbox no MSFlexgrid ou MSHFlexgrid
Postada em 22/8/2007 por ghost_jlp            
Realmente muito simples e prático, parabéns ao autor!!
***************************************************
Para rodar o exemplo abaixo crie um projeto, coloque um flexgrid e cole o código abaixo:

Const strChecked = "þ"
Const strUnChecked = "q"

Private Sub Form_Load()
        With MSFlexGrid1
            .Rows = 10
            .Cols = 3
            
            .AllowUserResizing = flexResizeBoth
                        
            'name the cols
            For i = 1 To .Cols - 1
                .Row = 0
                .Col = i
                .Text = "Column " & i
            Next i
            
            'name the rows
            For i = 1 To .Rows - 1
                .Col = 0
                .Row = i
                .Text = "Row " & i
            Next i
                        
            'define fields as checkbox
            For y = 1 To .Rows - 1
                For x = 1 To .Cols - 1
                    .Row = y
                    .Col = x
                    .CellFontName = "Wingdings"
                    .CellFontSize = 14
                    .CellAlignment = flexAlignCenterCenter
                    .Text = strUnChecked
                Next x
            Next y
        End With
    
End Sub

Private Sub Form_Resize()
    MSFlexGrid1.Width = Me.ScaleWidth
    MSFlexGrid1.Height = Me.ScaleHeight
End Sub

Private Sub TriggerCheckbox(iRow As Integer, iCol As Integer)
        With MSFlexGrid1
            If .TextMatrix(iRow, iCol) = strUnChecked Then
                .TextMatrix(iRow, iCol) = strChecked
            Else
                .TextMatrix(iRow, iCol) = strUnChecked
            End If
        End With
End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Or KeyAscii = 32 Then 'Enter/Space
        With MSFlexGrid1
            Call TriggerCheckbox(.Row, .Col)
        End With
    End If
End Sub

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 1 Then
        With MSFlexGrid1
            If .MouseRow <> 0 And .MouseCol <> 0 Then
                Call TriggerCheckbox(.MouseRow, .MouseCol)
            End If
        End With
    End If
End Sub

'********************************************************
autor: Chris Pietschmann
site: http://PietschSoft.itgo.com
fonte (com o exemplo): http://www.planet-source-code.com/URLSEO/vb/scripts/ShowCode!asp/txtCodeId!43129/lngWid!1/anyname.htm
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página