-
Note: I am posting this in both the General and Database forums.
Scenario: I've got an MSFlexGrid bound to a DataControl pointing to a particular table in an Access database. I've got the grid set up to select by row. The user can select multiple rows (contiguous only) by dragging with the mouse; this is fine.
Having hardly ever used the MSFlexGrid control, I am unfamiliar with how to use its numerous properties. All I want to do is the following:
(1) Find what rows the user selected
(2) Extract data from particular cells in those selected rows.
Can someone give me hand? Thanks in advance.
-
Hi Bruce
I haven't done much with the FlexGrid either except display data from an sql statement.
The answer to your first question..."what the user selected"
you use MouseRow (or MouseCol).
If Grid1.MouseRow = 3 Then MsgBox"User selected Row3"
As for the second question... "extract data", the Grid is really designed for displaying data rather than extracting or entering stuff. You can use the Clip property to transfer data to the clipboard where the values are stored as text, so that might be useful.
Hope thats been some help, sorry I can't help any further
GRAHAM :)
-
Hi Graham! I very much appreciate you responding to my post, since I often seem to pose questions that don't generate many responses (I was beginning to get a complex).
Anywho, after further research I was able to figure out how to do what I needed to do. ...And the results of my findings are as follows (Peter Criss, drum roll please) :
(1) Your suggestion on using the MouseRow/MouseCol properties work best when you want to grab (read) the data at one particular cell; this is good to know, but not what I wanted to do for this problem. What I wanted to do is find the starting and ending row for the range of rows the user selected. The starting row is given by the Row property and the ending row is given by the RowSel property.
(2)When I say I want to "extract" data, I mean I want to read the data that's in a particular cell so I can stick it in a variable and use it for further processing. To do this, you have to set the Row and Col properties of the grid, then the content is given by the Text property.
My real project is at work, but here at home I slapped together an example that will do what I want:
Code:
'command button clicked after user selects a range of rows ...
Private Sub Command1_Click()
Dim intFirstRowSelected As Integer
Dim intLastRowSelected As Integer
Dim intX As Integer
Dim strItem1 As String
Dim strItem2 As String
intFirstRowSelected = MSFlexGrid1.Row
intLastRowSelected = MSFlexGrid1.RowSel
For intX = intFirstRowSelected To intLastRowSelected
MSFlexGrid1.Row = intX
MSFlexGrid1.Col = 1
strItem1 = MSFlexGrid1.Text
MSFlexGrid1.Col = 2
strItem2 = MSFlexGrid1.Text
Debug.Print strItem1, strItem2
Next
End Sub
Again, Graham, I appreciate your efforts and hopefully we both learned something about MSFlexGrid.