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
Solved

Placing Checkboxes in flexgrid

Posted on 2003-11-19
7
1,705 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

856 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