Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Command button in grid
Message
From
23/02/2001 05:24:20
 
 
To
22/02/2001 17:55:08
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00478641
Message ID:
00478738
Views:
26
Hi!

This way you will get only one picture from proper to the first row of the table used in grid that will be replicated to all other rows in grid.

The technique of making dynamic changing of something in grid is another. What you did is just changed a one object. And this is only one object in grid. Grid does not makes as many objects as rows in it. So, to draw grid rows it uses the appearance of that single object. Is there a way to change appearance of that object for each row? Yes! Column object of grid have properties like dynamic*. They allow to specify different properties of the control and column for each row. It works by following way:

- Column evaluates all expressions in the Dynamic* properties
- changes properties of column properly to evaluated values
- draws the row
- moves the record pointer in the cursor (amazingly, this does not cause automatic updates!)
- repeat for next rows.

How to define expression in the Dynamic* property that is depended on some fields of the table? Use iif() function. For example, you can change background color of the row depended on the status using following expression put into the DynmicBackColor of all grid columns:

iif(MyAlias.StatusField = 'hold',RGB(255,255,0),iif(MyAlias.StatusField = 'approve',rgb(0,0,255),iif(MyAlias.StatusField = 'reject',rgb(255,0,0),rgb(255,255,255))))

This will cause yellow row for hold status, green for approve, red for reject and white for all other rows.

However, when you explore all Dynamic* properties, you will not find the appropriate property you need for your particular task. This because there are so many controls in VFP that represending for each property of tehse controls Dynamic* properties of column will cause too mych Dynamic* properties. there is a generic approach, however, that will allow you to refresh property theoretically any control in grid (even another grid or page frame) for each row. The approach is simple - usesome Dynamic* property of column and put custom function in its expression (UDF) that will be called for each row. For example:

MyGrid.DynamicBackColor = "thisform.RefreshButtonForEachRow()"

In that function you can change any property of the control you need. For example, the code you put in the Init method you should move to the custom method thisform.RefreshButtonForEachRow():
* RefreshButtonForEachRow() - refresh button in the grid's column for each row
if MyAlias.StatusField='hold'
  thisform.grid1.column1.command1.picture='yellow.bmp'
else
  if MyAlias.StatusField='approve'
    thisform.grid1.column1.command1.picture='green.bmp'
  else
    if MyAlias.StatusField='reject'
      thisform.grid1.column1.command1.picture='red.bmp'
    endi
  endi
endi
return RGB(255,255,255) && return correct back color as required for DynamicBackColor property
One note - don't base such code on the value of the textbox field in grid. Grid wirks with data in some cursor (alias), so take data from there. Taking data from the properties of other controls might not work, just because these properties might not be refreshed yet for current row in grid when you dynamic function running. The most reliable way is to use pure data from the cursor/alias usef for grid.

Finally, not that dynamic function should be made as efficient as possible, because it called for each row of visible part of grid. When it works slow, it will work **. Fr example, instead of use RGB() function replace it by pure integer value. Just type '? RGB(255,0,0)' in the command window and you will get an integer value of color that you can use for all color properties in controls. There are many other tricks to improve speed of function running, but this goes out of this topic.

Good luck!


>please help.
>
>in my table, i have a field -jsts- to capture the status of a job with three choices - hold,approve,reject. i add a column in a grid which is part of a formset to display them graphically via an embedded command button.
>
>the code of the command button in the init pem of the grid is
>
>if thisform.grd1.column1.text1.value='hold'
> thisform.grid1.column1.command1.picture='yellow.bmp'
>else
>if thisform.grd1.column1.text1.value='approve'
> thisform.grid1.column1.command1.picture='green.bmp'
>else
>if thisform.grd1.column1.text1.value='reject'
> thisform.grid1.column1.command1.picture='red.bmp'
>endi
>endi
>endi
>
>the column's pem are:-
>CurrentControl=Command1
>ControlSource=jsts
>sparse=.f.
>
>but the bmp are not displaying properly. where did i go wrong? ta
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform