Solved

VB6 multiple selections from msflexgrid to array with checks

Posted on 2007-03-29
5
497 Views
Last Modified: 2013-12-20
Hi,

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.






0
Comment
Question by:DennisPost
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:TreyH
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.
0
 
LVL 2

Author Comment

by:DennisPost
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
    rsInvLines.MoveFirst
    Do While rsInvLines.EOF = False
        ValRows(i).DetID = rsInvLines!DetID
        ValRows(i).RegNr = Me.txtNum
        i = i + 1
        rsInvLines.MoveNext
    Loop
   
    '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.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21737329.html
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20803581.html
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_11819218.html
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20313081.html

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


0
 
LVL 6

Accepted Solution

by:
nirojexpert earned 500 total points
ID: 18923399
denispost,

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
.column(0).width=0
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
else
   .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)
      else
               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
0
 
LVL 2

Author Comment

by:DennisPost
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!
0
 
LVL 6

Expert Comment

by:nirojexpert
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

696 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