?
Solved

Placing Checkboxes in flexgrid

Posted on 2003-11-19
7
Medium Priority
?
1,729 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

765 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