rsakhamu
asked on
MsflexGird - Selection of Rows using Crrl and Shift
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
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
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.
ASKER
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.
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.
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.
ASKER
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.
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.
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>.
<----- Code Begin ----->
Private Sub MSFlexGrid1_Mouseup(Button
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>.
ASKER
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.
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.
ASKER
Adjusted points from 120 to 140
ASKER
Hi wsh2,
Please try to answer this question I am badly need the implementation
Thanks
Please try to answer this question I am badly need the implementation
Thanks
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>.
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>.
ASKER
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.
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.
ASKER
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.
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.
ASKER
Hi wsh2,
Please try to answer my problem asap. I am badly need this implementation.
Thanks
Please try to answer my problem asap. I am badly need this implementation.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.