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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexGrid - Highlighting a row,

Status
Not open for further replies.

Chance1234

IS-IT--Management
Jul 25, 2001
7,871
US
Hopefully this is the last question i have regarding flexgrid controls for now, thanks to everyone so far who have answered to my other posts concerning pesky grids.

I am looking for a good way to highlight a row when a user clicks in a cell on that row, plus can also hihglight a row added by code (to the bottom)




Filmmaker, gentlemen and East end club promoter



 
You can set the selectionj mode property to 1 -By Row.

Or change the cellbackcolor property to add colour to more than one row.

Code:
'// Change the font of a row.
   MSFlexGrid1.Row = 3
   MSFlexGrid1.Col = 0
   MSFlexGrid1.RowSel = 3
   MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
   MSFlexGrid1.FillStyle = flexFillRepeat
   MSFlexGrid1.CellFontBold = True
   MSFlexGrid1.Row = 4
   '// change the back and fore colour of a row.
   MSFlexGrid1.Row = 4
   MSFlexGrid1.Col = 0
   MSFlexGrid1.RowSel = 4
   MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
   MSFlexGrid1.FillStyle = flexFillRepeat
   MSFlexGrid1.CellForeColor = vbWhite
   MSFlexGrid1.CellBackColor = vbRed
   MSFlexGrid1.Row = 5


Thanks and Good Luck!

zemp
 
ok... this is the bit im having a problem with,

The user can delete and add rows in the grid, via a couple of buttons on the form, now when the user clicks a cell i want it to highlight, blue for arguments sake. and all the other rows white until i click inanother cell then its all change again, where im having the problem is im occasionally getting a row still coloured after clicking on another row







Filmmaker, gentlemen and East end club promoter



 
Or you can use

Code:
   Grid.Row = Row_You_want
   Grid.Col = 0
   Grid.ColSel = Grid.Cols - 1

and if you want to change the selection color, you can use

Code:
  Grid.BackColorSel = color

David.
 
What are your design time setting for the following properties, .highlight, .FocusRect and .SelectionMode.

If I understand you correctly try setting them as follows,

Highlight = 2 - With focus
FocusRect = 0 - None
SelectionMode = 1 - By Row

You may not need any code.

Thanks and Good Luck!

zemp
 
that only seems to highlight one cell. also i think i definetly need the selctionmode to be free.

This is the code i have which is called from the procedures to add mouse down and some other buttons which do stuff!

The problem with this is that it doesnt always seem to work, mbpreviousselected row is a variable that is set each time the code behind these procedures are run, i really dont like it as i think this is where the problem is, so looking to find a solution to replace it.

Sub subChangecolours(IntColourSelection As Integer, Optional IntRowRef As Integer)
Dim IntCnt As Integer ' Integer counter for looping through.
Dim intNewRow As Integer
Dim intNewCol As Integer
Dim intThisRow As Integer
'Changes colours of rows in MSflexGrid control
'******************

'Set Colour white & Blue

Select Case IntColourSelection
Case 1 ' add
If mPrevSelectRow > 0 And grdTimesheet.Rows - 1 >= mPrevSelectRow Then
grdTimesheet.Row = mPrevSelectRow
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = vbWhite
Next IntCnt
End If
With grdTimesheet
.Rows = grdTimesheet.Rows + 1
.SetFocus
.Row = grdTimesheet.Rows - 1
.Col = 1
End With

lstFlag.List(grdTimesheet.Row - 2) = "Blank" & _
Str(grdTimesheet.Row - 2) 'add a line to maintain array size
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = &HFFFFC0
Next IntCnt
Case 2
'SPARE WAS DELETE BUT SURPLUS
Case 3 'Selected row (via Mouse down)

If grdTimesheet.Rows > mPrevSelectRow And mPrevSelectRow > 0 Then
grdTimesheet.Row = mPrevSelectRow
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = vbWhite
Next IntCnt
End If

intThisRow = IntRowRef

If intThisRow > 1 Then
grdTimesheet.Row = intThisRow
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = &HFFFFC0
Next IntCnt
End If

Case 4 ' New Instruction, Task,Client
If mPrevSelectRow > 0 Then
grdTimesheet.Row = mPrevSelectRow
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = vbWhite
Next IntCnt
End If
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = &HFFFFC0
Next IntCnt
mPrevSelectRow = grdTimesheet.Row
End Select

End Sub


Filmmaker, gentlemen and East end club promoter



 
If the selection mode must remain free then I think you will need to loop through the rows and set the colour to the unselected colour and then set the colour of the row you want to be selected. It's not very elegant and may cause your your grid to 'flash'. But I can't think of any other method.

I would start the procedure by Clearing all rows of the selected colur and then set it accordingly.

Thanks and Good Luck!

zemp
 
for the record i have ended up with this, and changing the order of a couple of my other procedures

Sub subChangecolours()
Dim IntCnt As Integer ' Integer counter for looping through.
Dim IntRCnt As Integer
Dim IntRow As Integer ' tracks the row we are on
'Changes colours of rows in MSflexGrid control
'******************

Application.ScreenUpdating = False

IntRow = grdTimesheet.Row

'set white
For IntRCnt = 2 To grdTimesheet.Rows - 1
grdTimesheet.Row = (IntRCnt)
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = vbWhite
Next
Next

'set blue
grdTimesheet.Row = IntRow
For IntCnt = 0 To grdTimesheet.Cols - 1
grdTimesheet.Col = IntCnt
grdTimesheet.CellBackColor = &HFFFFC0
Next


grdTimesheet.Row = IntRow

Application.ScreenUpdating = True
End Sub

Filmmaker, gentlemen and proffesional drinker



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top