Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Highlight record in grid
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00939852
Message ID:
00940007
Views:
19
as Marcia said, if you're using VFP8 or later the task is quite simple, however if you are using less than that, the option could be the gridhighlighter, but if you want to know how it works, then start where I started , in the FAQ section in this site. here the content of that

Frequently Asked Questions


FAQ ID: 8092 Created on: June 20, 2001 14:00 Updated on: July 28, 2004 00:28





Title

How to make a grid appear like a list similar to list box

Summary

This article describes how to configure grid to appear as a list similar to the list box or the drop-down list of combo box. It is for appearance only. All other things are as usual for any grid.

This is useful for case when need to replace list box by a grid to display more records, because listbox is slow when displaying 1000+ rows in listbox.

Description

Assume we have a grid with 2 columns based on the alias with all default controls in it and ability to alter certain events of grid (the most simple case). Look also to comments in code for designing.
* Grid.Init
&& add a property to the grid to track the highlighting row
this.AddProperty("nGridRecNo")
this.nGridRecNo = 0

this.DeleteMark = .F.
this.RecordMark = .F.
this.HighLightRow = .F.
* this.SplitBar=.F. && Set up this in design time, cannot change this in run-time.
this.ScrollBars = 3 && or 2 if all columns fit into the visible area
&& If you have no horizontal scrollbar, last grid column width should be 1 point less than
&& required to fit last column into the visible portion of grid (1 point gap between the right
&& edge of the last column and the left edge of the scrollbar). This to avoid grid auto-scroling
&& (jumping) when cell in the last column is selected

this.GridLines = 2 && vertical

setupcolumn(this.Columns(1))
setupcolumn(this.Columns(2))

* Grid AftreRowColChange event code
if this.nGridRecNo<>recno(this.RecordSource)
  this.nGridRecNo = recno(this.RecordSource)
  this.Visible = .T. && (UPDATED) was this.Refresh
        && setting this.Visible is enough. This will refresh the 
        && highlighting row correctly, but works more quickly than 
        && this.Refresh because it does not re-read the data to determine
        && if rows should be re-arranged accordingly to filtering/sorting.
endif

&& note that you can use Grid Highlighter to highlight current row

procedure SetupColumn && make it as a form or grid class method
lparameters poColumn
&& assuming default textbox is in the grid
lnColor = RGB(0,200,200) && or whatever color you want for row highlighting
with poColumn
  .Movable = .F.
  .Resizable = .F.
  .ReadOnly = .T.
  .DynamicBackColor = "iif(recno('" + .parent.RecordSource + "')=this.nGridRecNo," + ;
    allt(str(lnColor))+ "," + allt(str(.BackColor)) + ")"
  .Text1.DisabledBackColor = lnColor
  .Text1.BackColor = lnColor
  .Text1.DisabledForeColor = .Text1.ForeColor
  .Text1.ReadOnly = .T.
  .Text1.Margin = 1 && required, so no jumping when selecting cell
endwith
You can also use the SetAll method to setup each column properties.

Now you can see the gray line under each selected cell, if selected row color is another than gray. It shows whatever under the grid on the form (usually the form surface). Put a shape or shapes under the grid and make background color of each shape the same as the color of the row highlighting for each column. Note that if any column has Sparse=.F., this will work by another way, however, usually it is not used in such grids.

Get rid of the text cursor. In the each text box GotFocus event put SET CURSOR OFF command. In the TextBox LostFocus event put the Set Cursor On command. I usually make special class for grid that contains that code, so no messing with 10+ textboxes to put code for each.

User can select the content of the read-only cell in the grid, then copy it into the clipboard. You can disable textboxes to disallow this. In addition, you can change the SelectedBackColor and SelectedForeColor so selection will not be visible (double click on the control will not show the entire cell selected for copying into clipboard).

There are also some other weird things you might want to workaround:

Click on the grid vertical line cause no record change - you can workaround it by writing code in Click event of the grid to change row manually using current mouse position (MROW() and MCOL() functions) and GridHitTest method to determine the relative row for positioning.

Mouse cursor is always text. You can change this by setting grid mouse cursor programmatically in the each column's MouseMove event. You can also put the transparent shape over grid with a lot of additional functionality to catch mouse clicks and forward them to the grid (you can find a sample of how to do this in the Fancy Tool Tip control that you can find in the downloads section), but this approach requires more programming.
.......
DO WHILE .T.
      ME.Work()
ENDDO
Previous
Reply
Map
View

Click here to load this message in the networking platform