Subject: Adding a Checkbox to a FlexGrid using VB 6.0
Posted By: foka Post Date: 9/26/2003 11:06:05 PM
Does anyone know how can I use check box inside the flexgrid using Visual Basic 6.0.

I want to check and uncheck some Information in a grid according to my business.

If some one knows how to do it pls tell me how can I do it
and pls send me the code of it.

My email Address is :
    mdfazlulkarim@yahoo.com
Reply By: beenaprashant Reply Date: 11/5/2004 4:14:29 AM
'''paste following code
''where
'''
''' grid1 is flexgrid control
''' chkSelect is Check box Control

Dim lrow As Integer
Dim lcol As Integer

Private Sub Grid1_Click()
    Select Case Grid1.Col
        Case 2: chkSelect.Visible = True
                chkSelect.Left = Grid1.Left + Grid1.CellLeft
                chkSelect.Top = Grid1.Top + Grid1.CellTop
                If Grid1.Text = "Selected" Then
                    chkSelect.Value = "1"
                Else
                    chkSelect.Value = "0"
                End If
                chkSelect.SetFocus
                chkSelect.Visible = True
        lrow = Grid1.Row
        lcol = Grid1.Col
    End Select
End Sub

Private Sub chkSelect_LostFocus()
  If chkSelect.Value = 1 Then
        Grid1.TextMatrix(lrow, lcol) = "Selected"
    Else
        Grid1.TextMatrix(lrow, lcol) = "Skip"
    End If
    chkSelect.Visible = False
End Sub


''' this will surely solve your problem
''' Best Luck !!!

Reply By: marcostraf Reply Date: 11/5/2004 2:11:32 PM
Just to add more documentation on Mr. Beena Brashant code (that is perfectly fine).

chkSelect must be added in the form with the Visible property set to False, no Caption, and sized very small.
The code will work only on column 2, the select case in the Click event must be changed to handle other columns/rows.
The check box is shown at the left of the cell. Text in the grid must be right aligned, or left padded with spaces to avoid being covered by the check box when visible.
Scrolling the grid when the check box is visible will not fire the chkSelect_LostFocus event. Call chkSelect_LostFocus from the Grid_Scroll event.

My preference is to use a context menu instead of a check box, using PopupMenu from the grid mouse down event (but that is just a preference)

Marco
Reply By: saravanan_article Reply Date: 3/8/2006 6:58:00 AM
Hi, I am using C#.. I tried the same way as per as ur code in VB,, But its not showing me the CheckBoxes.. Please tell me Where is the problem in my code.. If u want my sample code, send me ur mail id.

My id is saravanan_article@yahoo.com


Please let me know


Regards,
Saravanan.


Go to topic 33049

Return to index page 349
Return to index page 348
Return to index page 347
Return to index page 346
Return to index page 345
Return to index page 344
Return to index page 343
Return to index page 342
Return to index page 341
Return to index page 340