Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


VB6 multiple selections from msflexgrid to array with checks

Posted on 2007-03-29
Medium Priority
Last Modified: 2013-12-20

Our inhouse software covers invoice registration amongst other things. (Visual Basic 6)
Operational people enter their expected costs on a per file basis.
When the actual invoice arrives, the finance department registers the invoice in their part of the system, then matches the "expected costs" entered by the operational people to the actual invoice.

At the moment the finance users can only select one line at a time and the confirm.
I would like them to be able to match multiple lines in one go.
The selections are made from a msflexgrid.

To start with I created:
Private Type RowsToValidate
   DetID as long ' ID of the expected costs table
   RegNr as long ' The invoice registration number
   FlexRowNr as Byte ' Flex line nr ' Don't know if this is even necessary
End Type
Dim ValRows() as RowsToValidate 'Rows to confirm

When the user clicks on the flex to make the selection I would like:
A check to see if it has already been selected. If so remove it from the array (Deselect)
If it hasn't been selected I want to add it to the array.

Once the user has made all the selections they want, they will click on a button to do the confirmation (Validation)
This will be done by a function. For this to work i'll need to know how many values are in the array.
Can I use something like:
FOR i = 0 to max(Array) ????
or should I use the recordset count from the rs used to fill the flex in the first place???

As this is the first time I have worked with types, arrays and multiple selections on flexgrids, I am having a trouble getting my head around the logic needed and the steps involved.

Thanks in advance for any help you can offer.

Question by:DennisPost
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
  • 2
  • 2
LVL 11

Expert Comment

ID: 18815723
Will the selections be contiguous or non-contiguous?
The MSHFlexGrid by design does not offer multiple non-contiguous cell selection. You would probably have to investigate a 3rd party control to do that.

Author Comment

ID: 18816261
Hi TreyH,

That's some bad news as they will be non-contiguous.
I just finished another sub to allow the users to validate all available "excpected costs". :

dim i as integer
    'Fill the array with values from the recordset
    i = 1
    Do While rsInvLines.EOF = False
        ValRows(i).DetID = rsInvLines!DetID
        ValRows(i).RegNr = Me.txtNum
        i = i + 1
    'Cycle through the array calling the function ValidateRows each time
    For i = 1 To intRSRows
        ValidateRows ValRows(i).DetID, ValRows(i).RegNr
    Next i

This will suffice,
but I would still like to realize my question.

I will try some of these EE checkbox in flexgrid answers.

I you have a better idea, please don't be shy about letting know about it. :-)


Accepted Solution

nirojexpert earned 2000 total points
ID: 18923399

you can use hidden columns to store the state of selections
for example
'while loading data set the first column;s visibility to off, rest columns contain your data.
with grid
end with

'when user click to make selection, you can do as
if .textmatrix(.row, 0) = "" then 'no selection so far
   .col = 1
   set .cellPicture = loadPicture("C:\selected.gif")
 .text = 1
   .col = 1
   set .cellPicture = loadPicture("C:\notselected.gif")
 .text = 0
end if

'now to find the selected ones
selID = ""
with grid
  for i= 0 to .rows-1
     if .textmatrix(i,0) = 1 'this is a selected row
      if selID ="" then
               selID = .textMatrix(.row, 0)
               selID = selID & .textmatrix(.row, 0)
      end if
   end if
  next i
end with
  idArray = split(selID, ",")

'so there is no restriction in how the user will make the selecetion
but the user has to click on the row to make the selection

Author Comment

ID: 18937598
Thanks Nirojexpert,

I am a little swamped with other higher priority work at the moment. I will try this out as soon as I can.

A few questions about your code though.
Where can I get these .gif files?
I assume SellID is just an integer value.
What kind of variable should the idArray be? Dim idArray() as String ??
I .col=1 contains the .text, this will not highlight the whole row then, right?
After I fill the idarray from Selid, how would I my array (ValidateRows ValRows(i).DetID, ValRows(i).RegNr)?

Thanks for your help!

Expert Comment

ID: 18944210
A few questions about your code though.
Where can I get these .gif files? it can be any. instead of c:\ make a folder "images " where exe is built and then use the app.path & "\images\selected.gif"

I assume SellID is just an integer value. you put the ID of the record that will identify the record.
What kind of variable should the idArray be? Dim idArray() as String ??
I .col=1 contains the .text, this will not highlight the whole row then, right? . highlighting the whole row will depend on the property of grid.
After I fill the idarray from Selid, how would I my array (ValidateRows ValRows(i).DetID, ValRows(i).RegNr)? you will probably need to modify the function such that it can accept the whole array like ValidDateRows(Rows() ), etc
upload your code blocks, i will be able to help further

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question ( 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…
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…
Suggested Courses

670 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