|
-
Mar 8th, 2010, 09:17 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
Dear all,
I have a msflexgrid. One of the column is "amount".
I want to know, is there any codes that i can multi-select the rows in the grid by clicking the left button of mouse while the [Ctrl] key is being pressing, then, there is a textbox that display the sum of the "amount" column of the selected row. (The behavior is just like "MS Excel")
Thank you a lot for your help in advance
I can still live in my current job because I am here 
-
Mar 8th, 2010, 10:09 AM
#2
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
If you set SelectionMode property to flexSelectionByRow then you will be able to select rows using SHIFT+ARROW keys or SHIFT+MOUSE.
MSFlexGrid1.SelectionMode = flexSelectionByRow
-
Mar 8th, 2010, 10:24 AM
#3
Thread Starter
Addicted Member
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
 Originally Posted by RhinoBull
If you set SelectionMode property to flexSelectionByRow then you will be able to select rows using SHIFT+ARROW keys or SHIFT+MOUSE.
MSFlexGrid1.SelectionMode = flexSelectionByRow
thanks. 
one more question: how to know which rows the user has selected and then calculated the sum of amount immediately and reflect this amount in a textbox?
I can still live in my current job because I am here 
-
Mar 8th, 2010, 11:35 AM
#4
Thread Starter
Addicted Member
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
Hi, further question:
I am not sure if "MSFlexGrid1.SelectionMode = flexSelectionByRo" equals to what i expect.
What i want is, in case the msflexgrid has 10 rows, I can randomly select Row 1, 4 and 5 only by clicking "mouse's left button" while the [Ctrl] key is being pressed. (not selecting Rows 1 to 5)
And there is a textbox outside the msflexgrid, this textbox will display the sum of the amount column in the rows that user has selected.
Thank you.
I can still live in my current job because I am here 
-
Mar 8th, 2010, 12:20 PM
#5
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
I can randomly select Row 1, 4 and 5 only by clicking "mouse's left button" while the [Ctrl] key is being pressed. (not selecting Rows 1 to 5)
Try this.
Place MSFlexGrid1 on a new form and simply run the form...
Code:
Option Explicit
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) _
As Long
Private m_booKeyCtrl As Boolean, m_booKeyShift As Boolean
Private Sub Form_Load()
Form1.Move Screen.Width * 0.1, Screen.Height * 0.1, _
Screen.Width * 0.8, Screen.Height * 0.8
With MSFlexGrid1
.AllowUserResizing = flexResizeColumns
.AllowBigSelection = False
.Cols = 4
.ColWidth(0) = 400
.FillStyle = flexFillRepeat
.FocusRect = flexFocusNone
.HighLight = flexHighlightNever
.Rows = 1
.SelectionMode = flexSelectionFree
Dim lngIndex As Long
For lngIndex = 1 To .Cols - 1
.ColWidth(lngIndex) = 1500
Next lngIndex
End With
Dim intIndex As Integer
For intIndex = 1 To 500
MSFlexGrid1.AddItem "" & vbTab & "x" & Format(intIndex, "000") & vbTab & _
Str(Time()) & vbTab & String(intIndex, "*")
Next intIndex
End Sub
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbShiftMask Then m_booKeyShift = True
If Shift = vbCtrlMask Then m_booKeyCtrl = True
End Sub
Private Sub MSFlexGrid1_Keyup(KeyCode As Integer, Shift As Integer)
With MSFlexGrid1
m_booKeyCtrl = False
m_booKeyShift = False
End With
End Sub
Private Sub MSFlexGrid1_RowColChange()
With MSFlexGrid1
Static booBusy As Boolean
If m_booKeyShift Or booBusy Then Exit Sub
booBusy = True
Dim intThisCol As Integer, intThisRow As Integer
intThisCol = .Col
intThisRow = .Row
LockWindowUpdate .hwnd
If m_booKeyCtrl Then
.Col = 1
.Row = intThisRow
.ColSel = .Cols - 1
.RowSel = intThisRow
If .CellBackColor = .BackColorSel Then
.CellBackColor = .BackColor
.CellForeColor = .ForeColor
Else
.CellBackColor = .BackColorSel
.CellForeColor = .ForeColorSel
End If
Else
.Col = 1
.Row = 1
.ColSel = .Cols - 1
.RowSel = .Rows - 1
.FillStyle = flexFillRepeat
.CellBackColor = .BackColor
.CellForeColor = .ForeColor
.Col = 1
.Row = intThisRow
.ColSel = .Cols - 1
.RowSel = intThisRow
.CellBackColor = .BackColorSel
.CellForeColor = .ForeColorSel
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
Dim intThisCol As Integer, intThisRow As Integer
intThisCol = .Col
intThisRow = .Row
Dim intNextCol As Integer, intNextRow As Integer
intNextCol = .ColSel
intNextRow = .RowSel
LockWindowUpdate .hwnd
'~~> Clear Screen
.Col = 1
.Row = 1
.ColSel = .Cols - 1
.RowSel = .Rows - 1
.FillStyle = flexFillRepeat
.CellBackColor = .BackColor
.CellForeColor = .ForeColor
'~~> Update Multiline
.Col = 1
.Row = intThisRow
.ColSel = .Cols - 1
.RowSel = intNextRow
.FillStyle = flexFillRepeat
.CellBackColor = .BackColorSel
.CellForeColor = .ForeColorSel
LockWindowUpdate 0&
Tag900:
.Col = intNextCol
.Row = intNextRow
End With
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 01:00 PM
#6
Thread Starter
Addicted Member
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
thanks, all 
Koolsid, so, how about sum() of an amount column of the selected row immediately in a textbox or label that outside the datagrid?
I have added the red line code, it seems the codes should be added there.. but i dont know how to reset the value if user de-select a row..
Private Sub MSFlexGrid1_RowColChange()
With MSFlexGrid1
Static booBusy As Boolean
If m_booKeyShift Or booBusy Then Exit Sub
booBusy = True
Dim intThisCol As Integer, intThisRow As Integer
intThisCol = .Col
intThisRow = .Row
'Assume column 5 is the amount field
g_total = g_total + .TextMatrix(intThisRow, 5)
Label1.Caption = g_total
Last edited by lok1234; Mar 8th, 2010 at 01:13 PM.
I can still live in my current job because I am here 
-
Mar 8th, 2010, 01:26 PM
#7
Re: [MSFlexgrid] How to multi-select rows with mouse's left click + [Ctrl] key?
how about sum() of an amount column of the selected row immediately in a textbox or label that outside the datagrid?
Hint:
1) Try and see which event is fired when you click on the row
2) If the row was not highlighted earlier then get the row number and once you get that, extract the value from the respective column
3) Add it to the textbox value...
4) If the row was highlighted earlier then get the row number and once you get that, extract the value from the respective column
5) Deduct it from the textbox value...
Give it a try. If you get stuck, post the code that you have tried and we will definitely help you
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|