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

change button caption in grid depending on content of a field 1

Status
Not open for further replies.

arielap

Technical User
Aug 2, 2003
71
GB
I have a grid with a command button in column 5,
The button caption is 'PDF' and clicking it opens a file whose name is in field DBFNAME of the open DBF.

What is wanted is for the button's caption to be grey if field DBFNAME is empty or blue if that field contains a filename.

I've tried putting IIF(empty(dbfname),....) lines + refreshes in the grid's before/after rowcolchange, and gotfocus. Unsucessfully.

Help please

 
Hello,

You've come across one of the VFP restrictions, for a grid at least!

You have to think outside the box a little...

Think about TWO buttons, and then use the dynamiccurrentcontrol function to display the one you want, (with the right caption, and enabled status) based on the field contents.

You could probably get away with an IIF() to do that

The form would need something like this in the init procedure:

Code:
THISFORM.myGRID.COLUMN1.DYNAMICCURRENTCONTROL = 'IIF(empty(mytable.myfilename),"command1","command2")'

You might need to look at the sparse property for the column too!


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
>>You've come across one of the VFP restrictions, for a grid at least!<<

Thanks - that explains why code that's fine for stand-alone command buttons would'nt work. Rethink required

 
When you use controls other than default text1 in grid, generally you don't need to use DynamicCurrentControl but simply a Dynamic* property of the column such as DynamicFontBold. You set it to a custom method and in that method you set the control's behavior. Check FAQ on:


and a recent sample using buttons:


Cetin Basoz
MS Foxpro MVP, MCP
 
Cetin,

You're right (of course) about Dynamic* proeperties such as DynamicFontBold. But I suspect what Areielap really wants is not to change the colour of the button dynamically, but to change whether or not it's enabled. There's no DynamicEnabled property, hence the suggestion to use DynamicCurrentControl.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Exactly Mike!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Mike,
I assume you are saying it without checking the FAQ and code I gave links for:) At least try the code on foxite.

There is not a DynamicEnabled I know, but DynamicFontBold is used as a trick just to get a handle to control's painting during refresh (Dynamic* are called whenever a refresh occurs).

PS: Sorry for giving links from other forums but those were the forums that I created those entries. I am very new here and don't know how to do many things.

Cetin Basoz
MS Foxpro MVP, MCP
 
Wow, you learn something new each day.

You can use the columns' DynamicFontBold property to call a function that changes the contents of the button caption and it's enabled state!

To test this, I created a quick form. Added a table in the data environment and dropped a grid on it.

I put a button in one of the columns, and set the sparse property to false. I then deleted the existing text control from that column.

I then added a new button to the form called button1 and modified the DynamicFontBold property for the column to this:
Code:
thisform.button1.click()

And in that buttons click method I put this:
Code:
thisform.grid1.column3.command1.Caption = myTable.MyField 

IF myTable.MyField = "ARCH"
	thisform.grid1.column3.command1.Enabled = .f.
ELSE
	thisform.grid1.column3.command1.Enabled = .t.
endif

It works a treat!

That is potentially SO useful, it could provide a pseudo 'dynamicpicture' feature... probably

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
The FAQ actually demos that with pictures:)

Cetin Basoz
MS Foxpro MVP, MCP
 
Cetin,

There is not a DynamicEnabled I know, but DynamicFontBold is used as a trick just to get a handle to control's painting during refresh (Dynamic* are called whenever a refresh occurs).

Ah, yes. I see what you are saying. Now I come to think of it, I've done this sort of thing myself.

Sorry for giving links from other forums but those were the forums that I created those entries.

There is no problem in linking to pages on other forums, provided they provide useful information (which is the case here, of course).

I am very new here ...

And very welcome.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you everyone - that's given me some pointers to experiment with.

Mike,
what my users actually want is to be able to see, from the colour of the command button's text, whether there is already a filename in a field used by the command button's method, or whether that field is empty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top