The MsFlexgrid control has an event 'SelChange'
It fires every time a user changes the selection.
this code
Code:
If MsFlexGrid.Row - MsFlexGRid.RowSel <> 0 then
'User selected more than one row
'So Make the row and selected row the same
MsFlexgrid.row = msflexgrid.rowsel
'To get highlight you must set focus to the control then back to whatever else
msflexgrid.SetFocus
End if
Hope that helps
Even if everybody spoke the same language, nobody would be speaking the same language.
it still lets me selects the rows except for that there will be 1 selected after mouse release or key realease. But i want it so that they cant even select multiple rows
Private bNoDrag As Boolean
Private Sub Form_Load()
MSFlexGrid1.SelectionMode = flexSelectionByRow
MSFlexGrid1.FocusRect = flexFocusNone
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then bNoDrag = True
End Sub
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If bNoDrag Then
MSFlexGrid1.Row = MSFlexGrid1.MouseRow
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
End If
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
bNoDrag = False
End Sub
I dont know whih settings your MS Flexgrid has: use
AllowBigSelection = true, FocusRect = flexFocusNone, Highlight = flexHighlightWithFocus
Its quiet normal for a Flexgrid that it has normaly highlighted one row, but when you press the Shift button and select a row with the mouse then you will per sure get a multiselection in a flexgrid. you only can cancel that by code
Code:
Private Sub myGrid_Click()
myGrid.RowSel = myGrid.Row
End Sub
But then, if you change Selection and press Shift together with mouse Leftclick the second line will do a short flash but the original selection will stay. This comes from that a Flexgrid normally selects all Lines between Row and RowSel. This is basically for a Flexgrid, and cannot be changed this way. If you only want to have permanent NO-Multiline-Selection you can only use: Highlight = FlexHighlightNever and then draein the selected line yourself. ( this is what in some cases I do )
Code:
'On the topmost of the Form write
Option explicit
Private m_LastSel as integer ' dont declare this variable in the function or it will not work' then we have the function
Private Sub SelectRow(iRow As Integer)
Dim i As Integer
With myGrid
' Firstwe unselect previous Selection (if there is one )
If m_LastSel > 0 Then
.Row = m_LastSel
For i = 0 To .Cols - 1
.Col = i
.CellBackColor = RGB(255, 255, 255)
.CellForeColor = RGB(0, 0, 0)
Next
End If
' now select new selection and destroy any multiselection as input is .RowSel Value' and you are setting roW = RowSel here
.Row = iRow
For i = 0 To .Cols - 1
.Col = i
.CellBackColor = RGB(0, 0, 255)
.CellForeColor = RGB(255, 255, 255)
Next
m_LastSel = iRow
End With
End Sub
Private Sub myGrid_Click()
SelectRow (myGrid.RowSel)
End Sub
Private Sub myGrid_SelChange()
SelectRow (myGrid.RowSel)
End Sub
Last edited by JonnyPoet; September 8th, 2006 at 06:03 AM.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
If MsFlexGrid.Row - MsFlexGRid.RowSel <> 0 then'User selected more than one row
'So Make the row and selected row the same
MsFlexgrid.row = msflexgrid.rowsel
'To get highlight you must set focus to the control then back to whatever else
msflexgrid.SetFocus
End if
msflexgrid.redraw = true
On the KeyDown event use this
Code:
If shift = 1 And (KeyCode = 38 Or KeyCode = 40) then
msflexgrid.redraw = false
else
msflexgrid.redraw = true
end if
And finally on the keyup event
Code:
If MsFlexGrid.Row - MsFlexGRid.RowSel <> 0 then'User selected more than one row
'So Make the row and selected row the same
MsFlexgrid.row = msflexgrid.rowsel
'To get highlight you must set focus to the control then back to whatever else
msflexgrid.SetFocus
End if
msflexgrid.redraw = true
Even if everybody spoke the same language, nobody would be speaking the same language.
If shift = 1 And (KeyCode = 38 Or KeyCode = 40) then
Debug.Print " I'm here"
msflexgrid.redraw = false
else
msflexgrid.redraw = true
end if
Hi Sabin ! Try it with a debug Statement ( I inserted in red ) It is never reached in my Grid. And BigSelection doesn't work that way it only selects one column when I try this in my Grid. So which properties have you set to get this working?
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
i forgot about changing selection with the keys, here's my version that handles that too:
Code:
Private bForceKeySel As Boolean, bForceMouseSel As Boolean
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift And vbShiftMask Then MSFlexGrid1.Redraw = False: bForceKeySel = True
End Sub
Private Sub MSFlexGrid1_KeyUp(KeyCode As Integer, Shift As Integer)
If (Shift And vbShiftMask) = 0 Then MSFlexGrid1.Redraw = True: bForceKeySel = False
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MSFlexGrid1.Redraw = False: bForceMouseSel = True
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
MSFlexGrid1.Redraw = True: bForceMouseSel = False
End Sub
Private Sub MSFlexGrid1_SelChange()
If bForceKeySel Or bForceMouseSel Then
MSFlexGrid1.RowSel = MSFlexGrid1.Row
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
End If
End Sub
Private Sub Form_Load()
MSFlexGrid1.SelectionMode = flexSelectionByRow
MSFlexGrid1.FocusRect = flexFocusNone
End Sub
bushmobile:
When i use your code i see no selection even when i only click 1 row.
JonnyPoet:
Your code makes everything i click blue. I can make more then 1 row blue and i cant unselect em.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.