Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select a row in 2nd flexgrid by clicking row in 1st flexgrid

Status
Not open for further replies.

sarahmc22

Programmer
Nov 30, 2000
36
US
Hi guys,

My problem is the following:

I have a form with two flexgrids. I would like the user to be able to click a row on msflexgrid1 and then programmatically select the same row on msflexgrid2. Right now with the following code, several rows get selected on the second flexgrid, similar to how the behavior would be with a SHIFT + left click.

Code:
sub msflexgrid1_Click()
msflexgrid2.rowsel = msflexgrid1.rowsel
end sub

Any ideas on how i can select only ONE row??

Thanks!
S
 

Mark,

with the code:

msflexgrid2.row = msflexgrid1.row

I get only the first column highlighted. I'm looking for the whole row to be hightlighted.

???,
S
 
You can either set the SelectionMode Property of MSFlexGrid2 to 'By Row' or manually set the Column selection with:

msFlexGrid2.col = 0
msflexgrid2.Colsel = msflexgrid2.Cols - 1


Mark
 
I still haven't got this to work. Selection mode is of course set to by row. the problem is still as indicated in the first post. trying: msflexgrid2.row = msflexgrid1.row
only highlights the first non-fixed cell in that row, but not the entire row...

still clueless,

S
 
HOWTO: Select and Unselect a Range of Cells in MSFlexGrid

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0

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


SUMMARY
This article demonstrates how to select a range of cells and how to unselect a range of selected cells using the MSFlexGrid control.



MORE INFORMATION
The Visual Basic documentation provides a good explanation in the Online Help of how to select a range of cells in a MSFlexgrid control. However, there is no such explanation for how to undo a selection that has already been made. The example below demonstrates both.



Step-by-Step Example
Start a new Standard EXE project. Form1 is created by default.


Click Components on the Project menu, check "Microsoft FlexGrid Control," and then click OK.


Add a MSFlexGrid control to Form1.


Add two CommandButtons to Form1.


Change the Caption property of Command1 to "UnSelect."


Change the Caption property of Command2 to "Select."


Add the following code to the module of Form1:

Private Sub Command1_Click()
' unselect a range
With MSFlexGrid1
' cancel selection by setting end points to start points
.RowSel = .Row
.ColSel = .Col
.SetFocus
End With
End Sub

Private Sub Command2_Click()
' select a range
With MSFlexGrid1
' Row and Col properties must be set before RowSel and ColSel
.Col = 0 ' start selection in this column
.Row = 2 ' start selection in this row
.ColSel = 1 ' end selection in this column
.RowSel = 4 ' end selection in this row
.SetFocus
End With
End Sub

Private Sub Form_Load()
With MSFlexGrid1
.Clear
.FixedCols = 0
.FixedRows = 0
.AddItem "mike" & vbTab & 10, 0
.AddItem "fred" & vbTab & 11, 1
.AddItem "jack" & vbTab & 13, 2
.AddItem "herman" & vbTab & 55, 3
.AddItem "irene" & vbTab & 88, 4
.AddItem "jane" & vbTab & 22, 5
End With
End Sub




Press the F5 key to run the project. Click on the "Select" button. You should see the middle of the MSFlexGrid selected.


Click on the "UnSelect" button, and note that the selection is undone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top