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

Change values in Grid column

Status
Not open for further replies.

guillermo88

Programmer
Jun 1, 2001
55
US
Hi,
I have table transactions. This table has a column status.
Status value can 'V','X' or ' '
In the grid I want to be able to display 'VOID' or 'CANCELLED' depending on the value of status.

I tried to put this code in the init event of the column
if transactions->status = 'V'
this.value = 'VOID'
else
if transactions->status = 'X'
this.value = 'CANCELLED'
endif
endif
But It's not working.

And also I want to change the color of the column to red/white when status = 'V'

 
You can place an immediate if in the control source property of the grid column holding the text for the column. For example, if the grid column name is Status, then in properties go to the text for the column Status and in the Control Source property place the code: (iif(transaction.status='V','VOID','Cancelled')), this assumes you only use two status conditions. The iif() can be extended to include other options if needed.

Can't help on the color thingy.
 
Hi kls1,

Thanks for your response. I tried that piece of code.
I went to column status wich is in my grid column5, in the text1.controlsource property I place the condition:
(iif(transfer.status='V','VOID','Cancelled'))

I didn't work. I am getting Cancelled for every row.

I tried also to remove the leading parenthesis
and I got this "data source for this object must be a variable reference"


 
hi,

I solved the similar problem in my app using another way. Let's use your case as an example.

1. A table named status is created with two fields, status and descrip as follows,
status descrip
V VOID
X CANCELLED

2. Place the following SQL statement into the RecordSource property of the grid and set the RecordSourceType property to 4-SQL statment,
select a.*, b.descrip ;
from transactions a, status b;
where alltrim(a.status)=alltrim(b.status)and;
!empty(a.status);
order by a.status;
into cursor cTemp

3. Place the field, Ctemp.descrip, into the ControlSource property of the grid column.

Now you will get all what you want.

Using this way to solve such a problem, you can add many status codes into the system later without change the source code program.


Peter W.
 
Hi Peter,
Thanks for your response. This is a different aproach.
I am going to give it a try.

Do you know how to change the color of any column based on that status column?

I have many forms and grids. I think I should create one grid class that hold the general features, they are basically colors. Do you know how to place a instance of that grid in a form? So far I created grids from forms not as a class (visually)

Thanks again Peter.
 
To change the font properties of a column, you use the dynamic... properties of the column.

So you would say something like:-

Code:
THIS.Parent.DynamicForeColor = IIF(THIS.Value = [VOID],RGB(0,0,0), RGB(0,255,255))

(The column is the text box's parent)

Hope that helps,

Stewart
 
Hi Stewart,
Where exacltly do you place that piece of code

THIS.Parent.DynamicForeColor = IIF(THIS.Value = [VOID],RGB(0,0,0), RGB(0,255,255))

 
Just looked at your response to my posting. Wonder if there is a typo somewhere. You say you tried (iif(transfer.status='V','VOID','Cancelled')) when your first post said the table name was transaction. If this is the case all would show Cancelled as if would equate as false.

Any help?
 
You put it in the init event of the text box in the appropriate column. Also, the RGB(0,0,0) should be in quotes - they are evaluated at run-time.

However, having experimented a bit, I'm not sure this is quite what you want. This changes the color of the whole column according to the value just in the first row.

You said:-
"And also I want to change the color of the column to red/white when status = 'V'"

Are you wanting to change the column colors or the row colors? Won't the status in some rows be 'V' and in others 'X'? In which case I would think coloring the whole column would be misleading?

To color a row, you would put this code in the init event of the form or grid....

Code:
THISFORM.MyGrid.SetAll("DynamicBackColor", "IIF(status='V', RGB(255,0,0), RGB(255,255,255))","column")

...notice that the whole IIF() is in quotes here.

This would set the back color (ie fill in the cells) with red if status='V' and the others in white. (actually filling in the cell in red looks rather horrible!).

Obviously, you could use any of the Dynamic... properties. Just make sure that the section in quotes returns the correct results type - a color number in this case, or a logical for DynamicFontBold and so on.

Hope this helps, get back again if not.

Stewart
 
Thanks a lot kls1,
you're right, I got wrong the table name.
Now it works fine.
 
Hi StewartUK,
"And also I want to change the color of the column to red/white when status = 'V'"

My mistake, I meant to change the color of the cell only.
But I like it better like this, change the whole row.
I tried it and it's working. Thanks a lot.

I have other grids init event set like this:

DODEFAULT()
This.SetAll("DynamicBackColor", ;
"IIF(recno(This.RecordSource)=THISFORM.nRecord, ;
RGB(128,255,255),RGB(255,255,192))","COLUMN")

when I place this

THISFORM.MyGrid.SetAll("DynamicBackColor", "IIF(status='V', RGB(255,0,0), RGB(255,255,255))","column")

it's overwritinng the previous colors

I tried to change the properties at design time
backcolor = 255,255,192 and
forcolor = 128,255,255
but didn't work.

Thanks again StewartUK







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top