Solved

MsflexGird - Selection of Rows using Crrl and Shift

Posted on 2000-04-04
13
470 Views
Last Modified: 2008-02-26
How to Implement Ctrl , Shift and Ctrl+Shift functionality in MsflexGrid Like Windows Nt Explorer.
I have written the Code to Implement Ctrl functionality and it is working fine.
By default MsFlexgrid is supporting Shift functionality.
I need the combination of Ctrl +Shift for selecting the Rows.
I will be able to highlight the Rows using Ctrl and Shift separately but I am getting the following problem.
If the user Selects some Rows using Shif [ Ex. from Row2 to Row5 ] then user presses Ctrl and then he selects Row 7 then the Already selected Rows Row3, Row4 and Row5 are not highlighted. Only Row2 and Row7 are highlighted.
Note : My requirement of  selection of Rows using Ctrl +Shift is like Windows NT explorer
0
Comment
Question by:rsakhamu
  • 8
  • 4
13 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 2683097
I think that you may be out of luck on this one, at least directly. The MSFlexgrid as far as I am aware only supports one selected area at a time. The DataGrid control supports multiple selbookmarks but the flexgrid doesn't. You could simulate this by setting the back/fore colors of each selected area as they are selected.
0
 

Author Comment

by:rsakhamu
ID: 2683679
I know MSFlexGrid is not Supporting Ctrl functionality, by default we are unable to select non Adjacent Rows and we will be able to select Multiple Rows using shift and we need to Do our own  Implementation for  Ctrl + Shift. I need the Implementation to do that.

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2685499
Bad News.. there is a bug.. <sigh>. When you hold down the Shift key.. the MsFlexGrid SelChange event only fires once (with the first row number) and none of the other rows you pass over gets passed to the Mouse Events. To get which row you ended up on, you are going to have to use the X Y coordinates of the MsFlexGrid Mouse Events to calculate which row you finished on.. <groan>.


From MSDN:
======================================
BUG: FlexGrid SelChange Occurs for Every Selected Row or Column
Last reviewed: December 17, 1998
Article ID: Q197582

--------------------------------------

The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0

SYMPTOMS
The SelChange event of the Microsoft FlexGrid control fires once for each row and/or column added to the selection.

CAUSE
Behavior of the FlexGrid control was modified to trigger the SelChange event every time a row or column was added to the selection.

In Visual Basic 5.0, the SelChange event fired only once when the selection was extended, regardless of the number of rows or columns in the selection.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

Create a new Standard EXE project in Visual Basic 6.0. Form1 is created by default.

Select Components from the Project menu. Select the Microsoft FlexGrid Control 6.0. Click OK to close the dialog, and add the control to the toolbox.

Place an instance of the FlexGrid control on Form1.

Add the following code to Form1:

      Private Sub Form_Load()
         MSFlexGrid1.Cols = 10
         MSFlexGrid1.Rows = 10
      End Sub

      Private Sub MSFlexGrid1_SelChange()
         Debug.Print "SelChange"
      End Sub

Press the F5 key to run the project. Click in one of the FlexGrid cells. Hold the left-mouse button down and extend the selection across several other rows and columns.

Look in the Immediate window: "SelChange" appears once for each column and row added to the selection.
NOTE: If this test is repeated in Visual Basic 5.0 with the Visual Basic 5.0 version of the MSFlexGrid control, the SelChange event would occur only once at the end of the selection process and regardless of the number of columns and rows added to the selection. The Hierarchical FlexGrid Control 6.0 (MSHFlexGrid) behaves the same as described above for the Visual Basic 5.0 version of the regular FlexGrid control.

REFERENCES
MSDN Library, Visual Basic 6.0 documentation

--------------------------------------
Additional query words: msflexgrid
Keywords : kbVBp kbVBp500 kbCtrl kbVBp600bug kbusage
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.  

Last reviewed: December 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

0
 

Author Comment

by:rsakhamu
ID: 2686337
Using the following two properties we can easily findout the selected Rows using shift.

 startrow = m_Grid.Row
 Rowsel = m_Grid.Rowsel

From StartRow To RowSel are the number of Rows selected using Shift.

I will be able to get Shift Funtinality correctly and I will be able get Ctrl functionality correctly only thing is combination is not working.
Ex.if the user presses Shift and selects the Rows in between 2 to 5 and using Crrl he selcys 7 and 9. But in this case Row 2, Row 7 and Row 9 are highligted and the Rows 3, 4 and 5 are not highlighted.
I will greatly appreciated if you provided the solution for the above problem.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2686428
This should give you an idea as to a workaround for the shift key problem. To a Standard.Exe Project.. add a MsFlexGrid (Name=MsFlexGrid1) and set its rows and columns property to anything you like. Copy and Paste the following in.. and give it a try.

<----- Code Begin ----->

Private Sub MSFlexGrid1_Mouseup(Button As Integer, Shift As Integer, x As Single, y As Single)
With MSFlexGrid1

   Static intLastRow As Integer
   If intLastRow = 0 Then intLastRow = 1
   
   If Not Button = vbLeftButton _
   Then
      Exit Sub
   End If

   .FillStyle = flexFillRepeat
   
   Dim intThisCol As Integer
   Dim intThisRow As Integer
   intThisCol = .Col
   intThisRow = .Row
   
   If Shift = vbCtrlMask _
   Then
      .Col = 1
      .ColSel = .Cols - 1
      If .CellBackColor = vbRed _
      Then
         .CellBackColor = vbWhite
      Else
         .CellBackColor = vbRed
      End If
      intLastRow = .Row
      .Col = intThisCol
      .Row = intThisRow
      Exit Sub
   End If
   
   .Row = 1
   .Col = 1
   .RowSel = .Rows - 1
   .ColSel = .Cols - 1
   .CellBackColor = vbWhite
   .Row = intThisRow
   .Col = intThisCol
   
   If Shift = vbShiftMask _
   Then
      intThisRow = .TopRow _
         + (Round(y / .RowHeight(.TopRow), 0)) _
         - 1
      .Row = intThisRow
      .Col = 1
      .ColSel = .Cols - 1
      .RowSel = intLastRow
      .CellBackColor = vbRed
   Else
      .Col = 1
      .ColSel = .Cols - 1
      .RowSel = intThisRow
      .CellBackColor = vbRed
   End If
   
   intLastRow = .Row
   .Col = intThisCol
   .Row = intThisRow
   
End With
End Sub

<----- Code End ---->

Yes, it does need a little work.. the colors have to be changed to those in the Windows pallet and the:

  intThisRow = .TopRow _
         + (Round(y / .RowHeight(.TopRow), 0)) _
         - 1

statement has to be refined for more precise positioning (ie.. Fixed Row Heights).. but this should give you a direction to go in.. <smile>.      

0
 

Author Comment

by:rsakhamu
ID: 2686941
Thanks wsh2 but I did't get the required functionality. I am getting the following problem.

Ex. Select Rows 1 To 4 using Shiftkey, release Shift Key and Press Ctrl Key and select Row 6 then the Rows 2,3,4 are unhighlighted. Only Row 1 and Row 6 are highlighted. I need to highlight Rows 1 to 4 and 6.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rsakhamu
ID: 2692277
Adjusted points from 120 to 140
0
 

Author Comment

by:rsakhamu
ID: 2693393
Hi wsh2,

Please try to answer this question I am badly need the implementation

Thanks
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2693519
rsakhamu.. the code above works fine here.. it sounds like you dropped the Exit Sub statement in the control key section.
   
   If Shift = vbCtrlMask _
   Then
      .Col = 1
      .ColSel = .Cols - 1
      If .CellBackColor = vbRed _
      Then
         .CellBackColor = vbWhite
      Else
         .CellBackColor = vbRed
      End If
      intLastRow = .Row
      .Col = intThisCol
      .Row = intThisRow
      Exit Sub ' <---- Check this line
   End If

Once again please check your code against what has been provided above.. or.. just copy nad paste your mouseup event here.. <smile>.
   
0
 

Author Comment

by:rsakhamu
ID: 2697874
Excellent It is working fine with the following workflow.
Shift using Mouse.

I am again getting the same Problem I mentioned in the Last Comment. If I Select Shift with Down Arrow instead of Mouse.
To reproduce the problem.

Press Shift and select the Rows using Down Arrow and then release Shift Press Ctrl, the selected Rows using Shift are not highlighted.
It will be greatful helpful if you could respond earlist.


0
 

Author Comment

by:rsakhamu
ID: 2699573
Hi wsh2,

The Exact Workflow to reproduce the problem is as follows.

Press Shift and select the Rows using Down Arrow and then release ShiftKey, Press Ctrl, the selected Rows using Shiftkey are not highlighted.

It will be greatly helpful if you could respond earlist.
0
 

Author Comment

by:rsakhamu
ID: 2700802
Hi wsh2,

Please try to answer my problem asap. I am badly need this implementation.

Thanks




0
 
LVL 14

Accepted Solution

by:
wsh2 earned 140 total points
ID: 2701981
LOTZ of changes.. but I KNOW you are going to like it.. <smile>.

<----- Code Begin ----->

Option Explicit

Private Declare Function LockWindowUpdate Lib "user32" _
   (ByVal hwnd As Long) _
   As Long

Private m_booKeyCtrl As Boolean
Private m_booKeyShift As Boolean

Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
   
   If Shift = vbShiftMask _
   Then
      m_booKeyShift = True
   End If
   If Shift = vbCtrlMask _
   Then
      m_booKeyCtrl = True
   End If

End Sub

Private Sub MSFlexGrid1_Keyup(KeyCode As Integer, Shift As Integer)
With MSFlexGrid1
   
   m_booKeyCtrl = False
   m_booKeyShift = False

End Sub

Private Sub MSFlexGrid1_RowColChange()
With MSFlexGrid1
   
   Static booBusy As Boolean
   If m_booKeyShift _
   Or booBusy _
   Then
      Exit Sub
   End If
   booBusy = True
   
   Dim intThisCol As Integer
   Dim intThisRow As Integer
   intThisCol = .Col
   intThisRow = .Row
   
   LockWindowUpdate .hwnd
   
   If m_booKeyCtrl _
   Then
      .Col = 1
      .Row = intThisRow
      .ColSel = .Cols - 1
      .RowSel = intThisRow
      If .CellBackColor = vbRed _
      Then
         .CellBackColor = vbWhite
      Else
         .CellBackColor = vbRed
      End If
   Else
      .Col = 1
      .Row = 1
      .ColSel = .Cols - 1
      .RowSel = .Rows - 1
      .FillStyle = flexFillRepeat
      .CellBackColor = vbWhite
      .Col = 1
      .Row = intThisRow
      .ColSel = .Cols - 1
      .RowSel = intThisRow
      .CellBackColor = vbRed
   End If
   
   .Col = intThisCol
   .Row = intThisRow
   
   LockWindowUpdate 0&
   booBusy = False
   
End With
End Sub

Private Sub MSFlexGrid1_SelChange()
With MSFlexGrid1
   
   If Not m_booKeyShift _
   Then
      Exit Sub
   End If
   
   Dim intThisCol As Integer
   Dim intThisRow As Integer
   intThisCol = .Col
   intThisRow = .Row
   
   Dim intNextCol As Integer
   Dim intNextRow As Integer
   intNextCol = .ColSel
   intNextRow = .RowSel
   
   LockWindowUpdate .hwnd
   
   ' Clear Screen
   .Col = 1
   .Row = 1
   .ColSel = .Cols - 1
   .RowSel = .Rows - 1
   .FillStyle = flexFillRepeat
   .CellBackColor = vbWhite
   
   ' Update Multiline
   .Col = 1
   .Row = intThisRow
   .ColSel = .Cols - 1
   .RowSel = intNextRow
   .FillStyle = flexFillRepeat
   .CellBackColor = vbRed
     
   LockWindowUpdate 0&
   
Tag900:
   
   .Col = intNextCol
   .Row = intNextRow

End With
End Sub

<----- Code End ----->

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now