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

PictureVal in a grid

Status
Not open for further replies.

vernpace

Programmer
Feb 22, 2015
209
US
Hi Everyone,

New around here. Not new to VFP, but this has me stumpt: Got this problem displaying image data in a grid (column Sparse set to .F.). Have a image control in a grid. Have an SQL Server table with images stored in a varbinary(MAX) field (vartimage). Have image.PictueVal.ControlSource set to =cursor.vartimage. Problem is that the grid shows all rows with the first image in the cursor - PictureVal does no reEval for each row.

This is probably old news to most of you, but I really need a solution for this. Due to security requirements we cannot store image data in files. I thought of writing the images to temp files and then using the Picture property, but that has problems, not to mention it being a real kludge. My experience is that 99% of the time, I have been able to find solutions using VFP. But I don't know if there is a solution for this. Any suggestions?
 
Image control is not a data bound control, it has no controlsource and value properties, but picture and - as you know - pictureval.

So you need to manually take care of setting pictureval for each record. You can do so by setting up a backstyle_access method (in the property editor check the access method) and in the backstyle_access method set the pictureval.

Bye, Olaf.
 
Hi Olaf,

Tried but no dice. Got a "Data type is invalid for this property" error. I remember using this technique years ago for something else and it seemed to work. Technically, this would be a VFP bug - maybe it was fixed! Also tried pictureval_access method, but didn't work.
 
Ok, got it working. Took a tip from a post by CetinBasoz:

In the Grid Init(): This.colImages.DynamicBackColor = "ThisForm.GetPictureVal()"
In method ThisForm.GetPictureVal(): ThisForm.grdImages.colImages.imgPicture.PictureVal = cursor.vartimage

Works great. Not too much code. Now I can go to sleep.
 
I don't know what you did in Backstyle_access(). But logically you finally have to return the image control backstyle property as return value of the access method. Otherwise you get the type error.

Likewise you have to return the Backcolor from the method Form.GetPictureVal() you exexcute via this setting. You just set the PictureVal as a hook on delivering either backstyle or the backcolor (or any other dynamic property).

Using some dynamic property of course also helps, as these properties are also accessed for each row processed, but image.backstyle has the advantage it's really only accessed when drawing the image.

Bye, Olaf.
 
Jockey,

Your suggested method is indeed simple, but doesn't it rely on the list of images being static? Given that the images are contained in a database table, wouldn't you assume that they could be updated dynamically, in which case the grid would not necessarily show any new or updated images?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Olaf,

Took your suggestion and modified the backstyle_access method to return the backstyle property after setting PictureVal. Works like a charm. I like this better than the other solution - cleaner code, self contained.

Thank You!
 
>self contained.
Yes, it's one less thing to do, you don't set a call to a form method, it's part of the image control.

You could of course also add the GetPictureVal method to the image control by defining your own image class, but you'd still need to set up a call to it. The grid accesses the backstyle property anyway, no call needed.

The advantage of the dynamic properties is they work more versatile for anything, backstyle and backstyle_access is rather image specific, though googling I find you can also use it, if you set a container as the currentcontrol, and you can put many things into a container.

Bye, Olaf.
 
Jockey,

Yes, that looks better, but it is pretty much what Olaf originally suggested, that is, using Backstyle_Access to select the image. The main difference is that Hans is putting the whole thing in a container, which is a good idea.

In fact, I do exactly that myself. I have a standard grid class with a single column. The column contains a container, and the container contains whatever mix of images and labels you want.

But thanks for reminding me about Hans de Groot's blog. It contains some useful stuff.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top