Results 1 to 6 of 6

Thread: Can I have checkbox in MSFlexgrid control?

  1. #1

    Thread Starter
    Member AnsMe's Avatar
    Join Date
    Sep 2001
    Posts
    63

    Question Can I have checkbox in MSFlexgrid control?

    I am using MSFlexgrid.....haven't used this control before. I have 3 columns and I need to display a checkbox in the last column. Is it possible? If yes then how?

    Thanx in advance.
    When you TELL THE TRUTH, you don't have to REMEMBER WHAT YOU SAID !!!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    yes and no... you cant simply just add one... but you can use a checkbox control and move it via code to the desired cell on the grid.. using a control array you could match the row number with the checkboxes index to reference the data for each one... the listview control offers a checkbox feature... but it puts it in front of all the rows.. you can't specify where it will go...

  3. #3

    Thread Starter
    Member AnsMe's Avatar
    Join Date
    Sep 2001
    Posts
    63
    Can you please provide me with some sample code as to how can I add check box (using control array) in MSFlexGrid ???

    Thanx in advance !!!
    When you TELL THE TRUTH, you don't have to REMEMBER WHAT YOU SAID !!!

  4. #4
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Although kleinma's method works, I don't like using the checkbox itself with the FlexGrid.

    I have written a function which will allow you to place a picture of a checkbox directly into a cell in the grid. Clicking the cell changes the pix from a checked checkbox to an unchecked checkbox. (You can also set a grayed checkbox).

    Sorry, but I don't have the code handy. I'll be happy to post it a little later, though.

  5. #5
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Ok, here's the function to simulate checkboxes in a flexgrid:
    VB Code:
    1. Public Sub FlexCheck(grid As Control, _
    2.                     CheckCol As Integer, _
    3.                     Optional ByVal CheckRow As Variant, _
    4.                     Optional ByVal CheckValue As Variant)
    5.                    
    6.     'init
    7.     If IsMissing(CheckRow) Then
    8.         If grd.MouseRow <> grd.row Then Exit Sub
    9.         CheckRow = grd.row
    10.     End If
    11.    
    12.     If IsMissing(CheckValue) Then
    13.         If grd.Text = "2" Then Exit Sub
    14.         CheckValue = Abs(grd.Text - 1)
    15.     End If
    16.    
    17.     With grd
    18.         .row = CheckRow
    19.         .col = CheckCol
    20.         .CellPictureAlignment = flexAlignCenterCenter
    21.         .CellAlignment = flexAlignRightCenter
    22.         .CellForeColor = .CellBackColor
    23.         Set .CellPicture = [COLOR=red]Form1.imgFlexCheck.ListImages(CheckValue + 1).Picture[/COLOR]
    24.         .Text = CStr(CheckValue)
    25.     End With
    26. 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:
    1. FlexCheck Form1.Grid1, 1, Grid1.Row, 0
    In the _Click event of the grid:
    VB Code:
    1. 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.

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width