Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Highlighting a row in MSFlexgrid

205| Mon, 02 Jun 2008 08:57:00 GMT| anonymous| Comments (4)
Is it possible to highlight a row in an MSFlexgrid control using code?

Keywords & Tags: highlighting, row, msflexgrid, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/211687/
 
«« Prev - Next »» 4 helpful answers below.
> Is it possible to highlight a row in an MSFlexgrid control using code?

If by "highlight" you mean show the row as selected here is a routine
that will highlight a specified row for a FlexGrid control named
MSFlexGrid1 (change this to the name of your FlexGrid)

Sub HighlightRow(WhichRow)
With MSFlexGrid1
.Row = WhichRow
.Col = .FixedCols
.ColSel = .Cols - 1
.SetFocus
End With
End Sub

On the other hand, if you want to change the BackColor of each cell in a
row, then consider this

Sub HighlightRow(StartRowNumber As Long, _
Optional RowColor As Long = vbYellow)
Dim SaveRow As Long
Dim SaveCol As Long
Dim SaveFillStyle As Long
With MSFlexGrid1
SaveRow = .Row
SaveCol = .Col
SaveFillStyle = .FillStyle
' Set the range to be highlighted...
' Row and Col must be set before RowSel and ColSel
.Col = .FixedCols
.Row = StartRowNumber
' Set the rest of the range to highlight
.RowSel = StartRowNumber
.ColSel = .Cols - 1
' Force change to all selected cells
.FillStyle = flexFillRepeat
' Cell properties
.CellBackColor = RowColor
.Row = SaveRow
.Col = SaveCol
.FillStyle = SaveFillStyle
End With
End Sub

Here, besides the row you want to highlight, you can optionally pass in
the color you want the background of the cells to be (the default is
yellow).

Rick - MVP

rick | Mon, 02 Jun 2008 08:58:00 GMT |

"Rick Rothstein" <rickNOSPAMnews...NOSPAMcomcast.net>'s wild
thoughts were released on Thu, 31 Mar 2005 22:27:02 -0500
bearing the following fruit:

>> Is it possible to highlight a row in an MSFlexgrid control using code?
>If by "highlight" you mean show the row as selected here is a routine
>that will highlight a specified row for a FlexGrid control named
>MSFlexGrid1 (change this to the name of your FlexGrid)
>Sub HighlightRow(WhichRow)
> With MSFlexGrid1
> .Row = WhichRow
> .Col = .FixedCols
> .ColSel = .Cols - 1
> .SetFocus
> End With
>End Sub

<SNIP>

What's with the setfocus Rick?

Jan Hyde (VB MVP)
--
Men always make passes at girls that drain glasses. (Henny Youngman)

[Abolish the TV Licence - http://www.tvlicensing.biz/]

jan | Mon, 02 Jun 2008 08:59:00 GMT |

> >> Is it possible to highlight a row in an MSFlexgrid control using
code?
> >
> >If by "highlight" you mean show the row as selected here is a routine
> >that will highlight a specified row for a FlexGrid control named
> >MSFlexGrid1 (change this to the name of your FlexGrid)
> >
> >Sub HighlightRow(WhichRow)
> > With MSFlexGrid1
> > .Row = WhichRow
> > .Col = .FixedCols
> > .ColSel = .Cols - 1
> > .SetFocus
> > End With
> >End Sub
> <SNIP>
> What's with the setfocus Rick?

I'm not completely sure; I took that code from an old posting of mine.
If I had to guess, I'd say I wanted to make sure the focus was on the
grid if the code was executed from somewhere outside of one of the
grid's events, say, from a CommandButton Click event. My thinking was
probably... if the programmer wanted a row highlighted, he/she probably
wanted to do something else with the grid immediately afterward. And, of
course, if the focus is already on the grid, executing that line won't
affect anything.

Rick

rick | Mon, 02 Jun 2008 09:00:00 GMT |

On Thu, 31 Mar 2005 22:27:02 -0500, "Rick Rothstein"
<rickNOSPAMnews...NOSPAMcomcast.net> wrote:

>> Is it possible to highlight a row in an MSFlexgrid control using code?
>If by "highlight" you mean show the row as selected here is a routine
>that will highlight a specified row for a FlexGrid control named
>MSFlexGrid1 (change this to the name of your FlexGrid)
>Sub HighlightRow(WhichRow)
> With MSFlexGrid1
> .Row = WhichRow
> .Col = .FixedCols
> .ColSel = .Cols - 1
> .SetFocus
> End With
>End Sub
>On the other hand, if you want to change the BackColor of each cell in a
>row, then consider this
>Sub HighlightRow(StartRowNumber As Long, _
> Optional RowColor As Long = vbYellow)
> Dim SaveRow As Long
> Dim SaveCol As Long
> Dim SaveFillStyle As Long
> With MSFlexGrid1
> SaveRow = .Row
> SaveCol = .Col
> SaveFillStyle = .FillStyle
> ' Set the range to be highlighted...
> ' Row and Col must be set before RowSel and ColSel
> .Col = .FixedCols
> .Row = StartRowNumber
> ' Set the rest of the range to highlight
> .RowSel = StartRowNumber
> .ColSel = .Cols - 1
> ' Force change to all selected cells
> .FillStyle = flexFillRepeat
> ' Cell properties
> .CellBackColor = RowColor
> .Row = SaveRow
> .Col = SaveCol
> .FillStyle = SaveFillStyle
> End With
>End Sub
>Here, besides the row you want to highlight, you can optionally pass in
>the color you want the background of the cells to be (the default is
>yellow).
>Rick - MVP

Thanks. Just what I needed.

kevin | Mon, 02 Jun 2008 09:01:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories