p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   How do i add checkboxes on Flexgrid ? (http://p2p.wrox.com/showthread.php?t=31749)

leo_vinay July 22nd, 2005 01:39 AM

How do i add checkboxes on Flexgrid ?
 
Hi !,
I need to add checkboxes in my flexgrid. The code is:

Code:


For i = 1 To rs.RecordCount - 1

            'Need to add code on this line
            'as checkboxes will appear in 1st column                       

            grid.TextMatrix(i, 1) = Day(rs(1)) & Space(1) & MonthName(Month(rs(1)), True) & Space(1) & Year(rs(1)) & ""
            grid.TextMatrix(i, 2) = rs(2)
            grid.TextMatrix(i, 3) = rs(3) & ""
            grid.TextMatrix(i, 4) = rs(4) & ""
            grid.TextMatrix(i, 5) = rs(5)
            grid.TextMatrix(i, 6) = rs(6) & ""
            rs.MoveNext
Next

I also saw the below thread related to this topic but here i need control array.

http://p2p.wrox.com/topic.asp?TOPIC_ID=4611

Regards,

Vinay



Raghavendra_Mudugal July 22nd, 2005 04:21 AM

Hello

Check this link
http://in.geocities.com/raghavendra_...oFlexGrid2.zip

It contains then vb project. I have written the code to add the
checkboxes to the MSHFlexgrid. It adds in the form of control
array.

Please check this and let me know.

Hope this helps.

With Regards,
Raghavendra Mudugal

leo_vinay August 1st, 2005 12:19 AM

Hi Raghavendra,

Thanks for the code. I can generate checkboxes on Flexgrid but now the problem arises when the records to be displayed are more than the one that can be accomodated in the flexgrid. In such case when i check any record (say nth record) and scroll down, then allways the nth checkbox in the flexgrid view is shown checked,though the record details are different. The flexgrid view (in relation to checkbox) seems fixed on scrolling down.

Let me explain it further. Suppose i check 2,3 and 6th record
in the flexgrid. When i scroll down then the corresponding 2,3 and 6th record in the current view are shown checked though the original 2,3 and 6th records have scrolled up. This view remains fixed till i scroll to the end.The values that I get of the checked checkboxes are those of the original ones.

Any idea how to fix this?

Regards,

Vinay

Raghavendra_Mudugal August 1st, 2005 02:04 AM

Hello Vinay

Yes, it works for only fixed set of rows. Because those checkbox are not part of the grid, it
just sits on the top of each cell positioning as if they are in the grid.

I am working on it and let you soon as i complete it.

And SORRY for incomplete code.

With Regards,
Raghavendra Mudugal

marcostraf August 1st, 2005 01:25 PM

I answer a similar thread just today:

http://forums.devx.com/showthread.php?t=145283

Marco

leo_vinay August 1st, 2005 10:52 PM

Hi Marco,

I've seen the icon solution elsewhere also. But my requirements are that in the flexgrid invoices will be displayed and the records with checked checkboxes should be flagged in the database on button click. In case of checkbox control i can name all checkboxes with their respective record ids and can retrieve the records that need to be flagged.

Can you please guide me to a different approach that i may use in case of image checkboxes, the main aim is to get the record ids(fetched from recordset) corresponding to checked records.


Regards,

Vinay


Raghavendra_Mudugal August 2nd, 2005 12:10 AM

Hello Vinay, In that case use this simple solution

Add a MSHflexgrid and copy and paste this code

Private Sub Form_Load()
s = Me.MSHFlexGrid1.Rows
For q = 1 To s - 1
    Me.MSHFlexGrid1.Col = 1
    Me.MSHFlexGrid1.Row = q
    Me.MSHFlexGrid1.CellFontName = "Wingdings"
    Me.MSHFlexGrid1.TextMatrix(q, 1) = "o"
Next
End Sub

Private Sub MSHFlexGrid1_Click()
If Me.MSHFlexGrid1.TextMatrix(Me.MSHFlexGrid1.RowSel, 1) = "o" Then
    Me.MSHFlexGrid1.TextMatrix(Me.MSHFlexGrid1.RowSel, 1) = "þ"
Else
    Me.MSHFlexGrid1.TextMatrix(Me.MSHFlexGrid1.RowSel, 1) = "o"
End If
End Sub

I guess, it must give you some anothere thought to approch.
Please check this and let me know.

Hope this helps

With Regards,
Raghavendra Mudugal

leo_vinay August 2nd, 2005 12:56 AM

Hi Raghavendra,

Your code adds a text in Wingdings which appears to be a checkbox.
What my requirements are:

Records are looped through the recordset and displayed in the flexgrid. The first column should have checkboxes corresponding to each record. On a button click all the records that are checked are processed and flagged in the database. So the basic requirement is to fetch the id (recordset field ) corresponding to each checked record. In case of checkbox control i can name each checkbox with the recordset id and can thus fetch the required value.

I hope I might be able to clarify my requirements.

Thanks for the help.

Regards,

Vinay


Raghavendra_Mudugal August 2nd, 2005 01:17 AM

Hello Vinay

I came to know your doubt and my previous posting is what it tells you to do.
Rather than using the check box, and checking for vbChecked or vbUnchecked,
and processing all the records from the flexgrid, just consider that Wingding
text "þ" (checked box) as that row is selected for processing and take all the
data what you want from that row and set the flag in the table.

It is better to think for alternate, rathar than adding checkbox control
100 times (and might depend on the recordcount of the recordset), go for
so easy way. I guess you are getting what i am truing to say.

Hope this helps


With Regards,
Raghavendra Mudugal

leo_vinay August 2nd, 2005 03:44 AM

Hi Raghavendra,

Thanks for that. One last final thing is left which is the nub of the problem.
I can display these checkboxes(Webdings) but how to fetch the record id (which is primary key in the table and is not to be displayed in the flexgrid). I do code mainly ASP where we set the value of checkboxes to that of the record field value and thus perform required operation on the checked ids.

But how to get Id in this case. Though i can hide one column (width=1) and put the id field value in that. Any better idea other than this?

Regards,

Vinay



All times are GMT -4. The time now is 10:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.