Solved

Placing Checkboxes in flexgrid

Posted on 2003-11-19
7
1,718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

718 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