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.
Printable View
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.
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...
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 !!!
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.
Ok, here's the function to simulate checkboxes in a flexgrid:
Also needed:VB Code:
Public Sub FlexCheck(grid As Control, _ CheckCol As Integer, _ Optional ByVal CheckRow As Variant, _ Optional ByVal CheckValue As Variant) 'init If IsMissing(CheckRow) Then If grd.MouseRow <> grd.row Then Exit Sub CheckRow = grd.row End If If IsMissing(CheckValue) Then If grd.Text = "2" Then Exit Sub CheckValue = Abs(grd.Text - 1) End If With grd .row = CheckRow .col = CheckCol .CellPictureAlignment = flexAlignCenterCenter .CellAlignment = flexAlignRightCenter .CellForeColor = .CellBackColor Set .CellPicture = [COLOR=red]Form1.imgFlexCheck.ListImages(CheckValue + 1).Picture[/COLOR] .Text = CStr(CheckValue) End With End Sub
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):
In the _Click event of the grid:VB Code:
FlexCheck Form1.Grid1, 1, Grid1.Row, 0
VB Code:
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.
I guess it would help if I actually attached the file that I said I did. Here it is...