Solved

Placing Checkboxes in flexgrid

Posted on 2003-11-19
7
1,698 Views
Last Modified: 2009-12-16
I have a MSFlexgrid in my VB form.It has one fixed row but no fixed column.When the form loads i want to place checkboxes in the first column of all the rows.The user should be able to select multiple rows in the flexgrid .When they select multiple rows the checkboxes in those rows should also get checked.Can anyone send me a sample code for the same?

Thanks in advance
0
Comment
Question by:scmmicro
  • 3
7 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9785491
Try this:

On an empty form create a checkbox, rename it to "Check", set its index to 0, and make it invisible.
Create Msflexgrid, and rename it to "Grid".

Paste this code, and run it:
--------------------------------------------------------------------
Dim RowSelected() As Boolean
Dim NumberOfCheckBoxes As Integer

Private Sub Check_Click(Index As Integer)
    If Check(Index).Value = 1 Then RowSelected(Index + Grid.TopRow - 1) = True
    If Check(Index).Value = 0 Then RowSelected(Index + Grid.TopRow - 1) = False
End Sub

Private Sub Form_Load()
   
   
    Grid.FixedRows = 1
    Grid.Cols = 5
    Grid.Rows = 30
    Grid.ScrollTrack = True
    ReDim RowSelected(Grid.Rows) As Boolean
   
    For X = 1 To Grid.Rows - 1
        If Grid.RowIsVisible(X) = True Then
            Load Check(X)
            NumberOfCheckBoxes = X
            Check(X).Visible = True
            Check(X).Left = Grid.Left + 200
            Check(X).Top = Grid.RowPos(X) + Grid.Top + 50
            Check(X).ZOrder (0)
         End If
   
    Next X

End Sub

Private Sub Grid_Click()
    Dim ClickedRow As Integer
   
    RowSelected(Grid.MouseRow) = True
       
    Call UpdateCheckboxes
End Sub

Sub UpdateCheckboxes()
    For X = Grid.TopRow To Grid.TopRow + NumberOfCheckBoxes - 1
        If RowSelected(X) = True Then
            Check(X - Grid.TopRow + 1).Value = 1
        Else
            Check(X - Grid.TopRow + 1).Value = 0
        End If
    Next X

End Sub

Private Sub Grid_Scroll()
    Call UpdateCheckboxes
End Sub
----------------------------------------------------------------

Theory behind this is following:

Steps:
 - Adjust the grid properties to your needs.
 - Create several checkboxes, so every visible row has one checkbox, position them where you want and make them visible.
 - When clicked on checkbox, calculate for which row it is currently assigned, and update the according array element (RowIsSelected(x))
 - When Grid is clicked, update the accordig array element (RowIsSelected), and update the checkboxes
 - When Grid is scrolled, just update the checkboxes

Now in order to see if a row is selected, use       If RowIsSelected(Desired_Row) = True Then     <do something>
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9785518
Add      Grid.FixedCols = 0      to Form_Load event.
0
 

Author Comment

by:scmmicro
ID: 9786794
Hi dbrckovi
i tried the sample which you provided.The checkboxes are not getting displayed at all in the grid.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9787222
I have tried the same example I posted, step by step as I described and it works fine.
Maybe checkboxes are displayed behind flex grid.    (Although,      Check(X).ZOrder (0)      ensures that they are moved to front)

Try changing the line:                     Check(X).Left = Grid.Left + 200    
                           to:                     Check(X).Left = grid.Left - 300
in Form_Load.

This will display them on the left side of grid.

Are you using VB.NET ?
I think VB.NET doesn't support Load to create new instances of controls.

I'm using VB6 and everything works.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10592322
PAQed, with points refunded (20)

Computer101
E-E Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now