URGENT
Hi FRIENDS,
Pls help me with this.
I need to display a form/dialog with any grid which contains only checkboxes in the first column and data in the other two columns.
And my goal is to retrieve ONLY the data from the columns where the checkboxes are checked.

pls view the jpg image attached here to get an exact idea of what the form must look like.

Kindly also provide me a sample code too.

THANKS!!!

Recommended Answers

All 15 Replies

The above attached image shows a sample of the type of data grid I require.
Kindly suggest and help. thanks.

You can try this:
(you'll need two images, one for checked, other for no checked boxes)

Private Sub MSFlexGrid1_Click()
 
  With MSFlexGrid1
    If Val(.TextMatrix(.Row, 0)) = 0 Then
      .TextMatrix(.Row, 0) = 1
      .Col = 0
      Set .CellPicture = LoadPicture("C:\CHECK.BMP")
    Else
      .TextMatrix(.Row, 0) = 0
      .Col = 0
      Set .CellPicture = LoadPicture("C:\UNCHECK.BMP")
    End If
  End With

End Sub

If someone knows how to implement a REAL checkbox in msflexgrid, please help here... This would be very interesting...


Good luck!
Sidnei

Of course, I forgot, you'll need to load the "UNCHECK" image for all line you create in the flexgrid. The code I wrote will function changing between the two images once the user clicks...

And to retrieve the data only for the "checked" columns, verify the cell value - I use TextMatrix to put a different value in the cell: 0 for "unchecked", 1 for "checked".

Cheers!
Sidnei

The ListView control, found in common controls 6.0, has the ability to display checkboxes...

Good Luck

The ListView control, found in common controls 6.0, has the ability to display checkboxes...

Good Luck

Dear vb5prgrmr,
I've tried with ListView but it shows only 1 column if checkbox is displayed.
Do any of you know the way to display multiple columns in ListView with the first column displaying checkboxes?
Thanks

You can try this:
(you'll need two images, one for checked, other for no checked boxes)

Private Sub MSFlexGrid1_Click()
 
  With MSFlexGrid1
    If Val(.TextMatrix(.Row, 0)) = 0 Then
      .TextMatrix(.Row, 0) = 1
      .Col = 0
      Set .CellPicture = LoadPicture("C:\CHECK.BMP")
    Else
      .TextMatrix(.Row, 0) = 0
      .Col = 0
      Set .CellPicture = LoadPicture("C:\UNCHECK.BMP")
    End If
  End With

End Sub

If someone knows how to implement a REAL checkbox in msflexgrid, please help here... This would be very interesting...


Good luck!
Sidnei

Thankz sidnei,
But is there any better/practical alternative? may be any control that can do the work?

That I know, VB6 didn't have any control that supply your needs...
Maybe a third-party control, but you'll need to search on the web and usually they're paid, not free.

I think that solution is not clean or practical, really; but, in some cases, we need to do some dirty work to achieve the objective... ;)


The other way, I think, is to create a customized ActiveX Control, using an array of checkboxes and a FlexGrid control, loading many checkbox as you need (number of checkboxes = number of records you have), and controlling all the behaviour by yourself into the ActiveX control. But it will consume time and effort that you probably don't want to waste in this...


Good luck!

Sidnei

Or, it is not practical too, but you may join the tip gave by vb5prgrmr...
But, instead of use one ListView Control, use two...

(Really, I don't believe I'm writing this...)

Make a ListView with the checkbox and one column.
Then put other ListView control closely of this first and, when the user clicks on an option in the first, "hard-code" to select the same option in the second.

Is not beuatiful, but may function like you want...


Best regards!
Sidnei

Not sure how to do it through code, but I do know that you can set up check boxes and number of colums through the property pages (Custom), above the name property. It has been such a long time since I have used that control, but I also know that it will allow you to also add icons if you have an imagelist control associated with it.

Good Luck

Hi,

2 of easiest ways..
Type 1:
Use MSFlexGrid, And Change the font of the column..
There is a Font called "Marlett' and it comes with all versions of windows, font "b" looks like a Check Mark, so change the font of the cell you are wanting to create a Checkbox..
Load the Data from Recordset: (Say RST is your Recordset..)

Dim i As Integer
With Grd
    .Rows = 1
    .Cols= 3
    .TextMatrix(0,0) = "Select"
    .TextMatrix(0,1) = "ID"
    .TextMatrix(0,2) = "Name"
    i= 0 
    RST.MoveFirst
    Do While Not RST.EOF
       i=i+1
       .Rows = i+1
       .TextMatrix(i,0) = RST("EmpID") & ""
       .TextMatrix(i,1) = RST("EmpName") & ""
       .Row =i
       .Col=2
       .CellFontName  = "Marlett"
       .CellFontSize = 12
       RST.MoveNext
    Loop
End With

'Togle between  Check/Uncheck, write This Code:
Private Sub Grd_Click()
    If Grd.Row > 0 And Grd.Col= 2 Then
        If Trim(Grd.Text) = "" Then
            Grd.Text = "b"
        Else
            Grd.Text = ""
        End If
    End If
End Sub

To check Selected when you are looping thru:

For i = 1 To Grd.Rows-1
    If Trim(Grd.TextMatrix(i,2))  ="b" then
             'Code For Checked
    Else
            'code For Unchecked
    End If
Next

Type II
Use a Listbox, with Style = "Checked"
Load the Listbox with ID and name together...

Regards
Veena

Okay, robbed part of this from vipin saxena's post in http://www.daniweb.com/forums/thread254613.html

Private Sub Form_Load()
Dim I As Integer, SI As ListItem

LV.Move 30, 30, 4500, 5000
LV.Checkboxes = True
LV.HideColumnHeaders = False
LV.View = lvwReport

LV.ColumnHeaders.Add 1, "Check", "Select", 1500
LV.ColumnHeaders.Add 2, "Field1", "Field1", 1500, vbCenter
LV.ColumnHeaders.Add 3, "Field2", "Field2", 1500, vbCenter

For I = 1 To 10
  Set SI = LV.ListItems.Add()
  SI.SubItems(1) = "Subitem 1"
  SI.SubItems(2) = "Subitem 2"
Next I

End Sub

Good Luck

Hey,
seems it possible to use more than one column in ListView control, with checkboxes...

Look at http://www.daniweb.com/forums/thread254613.html

Great!
Another one for my collection...

Dear Friend,
This works good.
But when the number of records are huge say, in units of lakhs ... then it take a lot of time to get display.
I think using any sort of bound or unbound grids would be better under such situations.
Hence, can we do similar stuff using grids?
Lets discuss ...
Thank you.

Thanks QVeen72,
Hope this works. Let me try this and I will reply.
THANKS

But when the number of records are huge say, in units of lakhs ... then it take a lot of time to get display.

Why would you want to show records up to One LAKH in a Grid...? You need to refine your selection process.. I dont think it can be of any use to show that amount of data.......
Even if you want to show, as far as I know, MSFlexGrid (and most of the Grids) can handle rows only upto 65k....

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.