?
Solved

msFlexGrid, Highlight Only one line

Posted on 2007-08-11
8
Medium Priority
?
390 Views
Last Modified: 2008-01-09
I am trying to use msFlexGrid in my VB6.0 project.  I have been succesful in defining and loading the grid on the form.  I would like my users to select one row on the grid.  based on the contents of the row they select, I will know what action to take.

Each line on the grid is mutually exclusive.  It only makes sense for the user to select one line at a time.

My testing was going great.  I would click (single click, left mouse button, release left mouse button) on a row and the correct action would be taken.  Then I tested by pressing and holding the left mouse button while I dragged through the msFlexGrid.  I then released the left mouse button.  The result: All the lines that I dragged through were highlighted.  The good news was that it only executed the 'click' event for the row I released the mouse button on, not every row that was highlighted.  The bad news is that I think/know that seeing all of the highlighted lines would be very confusing to the user.  They shouldn't be able to select/highlight more than one line.

I looked for but didn't find a property similar to the multi-select/single select for listboxes that would control this behavior.  I searched EE and found a post that I thought was asking the same question.  The accepted answer on that post was to put the following code in the click event of the flexGrid.

With msfFlexGrid
 .RowSel = .Row
 .ColSel = .col
End With

This was an impovement. sort of.  The result of that code was the no line was ever highlighted, even if I clicked on a just a single line. I would like the 'clicked' line to be highlighted, just not all of the 'dragged over' lines.  Is there some way to ensure that only one row can be selected/highlighted at a time?  Even if the user drags the mouse while holding the left button down, I  would prefer that only one row be higlighted at a time.  If that can't be accomplished, would it be possible to make sure that only the row they ended up on when the mouse button was released is highlighted when the drag is complete?  At least then the user would only see one highlighted line and they would know which action was initialted.

0
Comment
Question by:mlcktmguy
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Expert Comment

by:weellio
ID: 19678153
something like this, maybe?
basically put the number of columns in an array
then make the first one highlighted only using an if statement


x = integer number of columns
dim cols(x-1)
for each x in cols
      if x = 0 then
            With msfFlexGrid
             .RowSel = .Row
             .ColSel = .col
            End With
      end if
next

0
 
LVL 38

Accepted Solution

by:
PaulHews earned 1000 total points
ID: 19678170
Set SelectionMode to be by row:

Flex.SelectionMode = flexSelectionByRow


Now in your click event:

Private Sub Flex_Click()
    With Flex
        .RowSel = .Row
    End With

End Sub
0
 
LVL 1

Author Comment

by:mlcktmguy
ID: 19678219
Thanks for the responses  I can't get weellio's to compile.

PaulHews:Yours shows promise.  It works as hoped on the single click items but it is out of synch on the 'drag' test. The good news is that it only leaves one line highlighted, even when I drag.  The prblem is that when I do the drag test,  It leaves the row that I began the drag highlighted but the click event is passed the row that the left mouse button was released on.

For example:  I begin my drag (left mouse button down and held) on row five.  I hold the mouse button down as I go thru rows 6, 7, 8, 9 and 10.  I release the button on row 10.  Row 5 is highlighted on the Grid but the result of the following statement: 'selRow = msfFlexGrid.MouseRow' is the click event of the grid puts the pointer to Row 10 in 'SelRow'.  When I pull the information to see what action to take I pull it from row 10, but row 5 is highlighted on the grid.

Seems very close to the correct answer but the click event needs to process the row that is highlighted on the grid.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 38

Expert Comment

by:PaulHews
ID: 19678296
>Row 5 is highlighted on the Grid but the result of the following statement: 'selRow = msfFlexGrid.MouseRow' is the click event of the grid puts the pointer to Row 10 in 'SelRow'.  When I pull the information to see what action to take I pull it from row 10, but row 5 is highlighted on the grid.

Don't use the MouseRow property...  Use the Row property...

Private Sub Flex_Click()
   
   
    With Flex
        .RowSel = .Row
        Debug.Print .Row
    End With

   
End Sub
0
 
LVL 19

Expert Comment

by:weellio
ID: 19678303
http://www.developerfusion.co.uk/forums/thread/94493/

or

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  Click = MSFlexGrid1.MouseRow
End Sub

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  ' select row to the first picked row only
  '
End Sub
0
 
LVL 3

Expert Comment

by:VR4
ID: 19678311
In you msfFlexGrid_MouseUp event put the following code:

msfFlexGrid.Row = msfFlexGrid.MouseRow
msfFlexGrid.RowSel = msfFlexGrid.MouseRow
msfFlexGrid.Col = 0
msfFlexGrid.ColSel = msfFlexGrid.cols - 1
0
 
LVL 3

Expert Comment

by:VR4
ID: 19678314
The above was meant for MSHFlexGrid, I would recomend using it over the regular one.
In any case your solution lies in MouseUP event, where at most you have to set the current selection to the one reported by the mouse.
0
 
LVL 1

Author Comment

by:mlcktmguy
ID: 19679233
Thanks for the responses, I had to get some sleep.  PaulHews: is awarde the points.
0

Featured Post

Independent Software Vendors: 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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

840 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