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

Image in a Grid 1

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,795
10
38
JP
Hi All,
I've been reading through some old posts for a solution, but it seems everyone approaches this a little differently.
So I have a table of documents, and I wanted to be a bit "clever" and show the icon associated with the file type. (Word, Excel, PDF, etc). The types are defined in another table that has the file type, extension and icon image associated with it.

So this means each document has a memo field which holds the path to the image type for the "icon" (We made them ourselves, not trying to retrieve them dynamically thought that would be really cool).

So I set up a 3 column Grid: Filename Extension Icon

In column 3 I removed the text box, and put in an image object instead. However, in the Image properties I tried to set Document.Icon (a memo field in the table that has a fully qualified path to the image location, such as T:\MyApp\Configs\FileIcons\Excel2007.PNG

I had expected that as the records were added to the row, the image class would show that .PNG automatically, just like when I point it's picture clause to This.Picture = Document.Icon. While that works at the form level, it doesn't work in a grid... how do I get this to show these by reference to the memo field? Most of the "solutions" I saw were hard coding image types into a field and using dynamiccontrol, but that seems to just pick between differently defined image objects in the column, and I have far to many file type icons for that... Plus I want the addition of new icons to be driven by our "FileType" table, instead of having to code them.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Dear Olaf,
NOW I GET IT. Sorry, finally. That last explanation was the gap I just didn't get until now. And it is working! (Ahhhhhh....)
While painful, I'm glad I hung in. Now I get it. Just totally missed it.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
No, you misread, Both columns "display" the same single cursor field, The column1 as text and column 2 actually is unbound, just via the myImage control it also addresses that filename memo to get the picture.

You can also have the picture first, if you set column2.columnorder=1.

This is just a demo. You can have whatever fields display in whatever columns, just the imagecontrol column should be an extra column not having a direct controlsource. You can play with the code and add a cursor field as second column and see whether that makes a change. I bet the image will just overrride the text or number or date or whatever second field of that column2, as the olumn2 only has one currentcontrol.

Bye, Olaf.
 
Yeah it does. In my grid, I've got 3 columns. So I saw that behavior before.

The fix in my case was simply to use the field in the table that has the image reference in it, which takes the place of the array that you create unbound. Now I get to fight with the next thing in getting the grid to look right. Have some oddity with text box in one field not aligning with the columns next to it. I changed the row height to be taller to accommodate the icon image, so will have to clean up the rest of it to get it to look right. Hopefully that's not as painful as getting it to show. :)


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Sorry, I meant to say "cursor".


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
OK, next up: Unbound?

If you don't already have all fields you want to display or use as the source of the picture property in a table, you create a cursor by a query to be bound to the grid. Whenever you access a field of an unbound alias, the grid does not skip through its records, so you won't have that cursor alias unbound. The only unbound thing I talked of is the column of the image, not the whole grid. The image class gets the picture from the same row as other columns anyway, as the grid moves the record pointer through the cursor, so also in an unbound column, you can access the current rows fields in code like backstyle_access, which is called for every row drawn.

Bye, Olaf.
 
Interesting.
As I implement this in other parts of the program, I'll keep that in mind.
But after 5 days, this form is finally working 100% the way that I want it to. This has been an education in GRID, a control I've previously avoided like the plague, but now I'm starting to get a right reasonable arsenal of good features out of for use across the application.
Cheers.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Scott24x7 said:
after 5 days, this form is finally working 100% the way that I want it to.

So you got it working or did you leave the image column out?

One problematic thing with images in the grid always is, that you only have one Rowheight for all rows. Havent tried setting that in backstyle_access, too, but I don't think it would work out.

Bye, Olaf.
 
I got it all working. Image column is in, and now I'm using the same technique in another form as well. Finally got a handle on it all. Thanks heaps for your patience with me on this.
RowHeight is now controlled by the GRID and then text boxes are set with .Textbox1.Height = This.grdControlGriid.RowHeight

So if it changes I don't have to update all of them. Since I only want icon to appear in the grid, I have control over the icon size, so I just make them all 24 height (the icon image). Then set RowHeight to 28 so there is some space between icons and rows. It works well.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Fine, very fine.

You don't need to set ColumnX.Text1.Height, the standard text1 box in grid columns resizes flawless without any visual artifacts. Only when you set Sparse=.F. where not necessary you may get artifacts of control borders showing up in the grid cells, but the normal text1 is only a white space in the grid and autoresizes with rowheight. You can think of grid cell rendering as only drawing the inner part of controls, the white space having the value is shown, the gridlines are making up the border. Up to Vista the active column was also showing the 3d border look of controls, only in the active row, since we got the flat look since Vista, that doesn't differ. With Sparse=.F. you set a mode drawing every row in the same mode noramally only shown in current row, and the effect can be seen especially wih comboboxes then having their dropdown arrow icon either in all rows or only the active. The Spareseproperty is named after that sparsely drawing so the grid looks cleaner than an array of normal controls would look.

Overall less is more, just think about it that way: If defaults were that bad, developers would have complained and MS would have changed, up to 2007 end of life announcement the MS team was very open to suggestions from the commuity. The grid is very mature and aside of the steep learning curve involved with its binding behaviour (google "vfp grid goes blank", a famous problem), defaults are normally just fine. What is a bit of annoyance is the default in regard of deletemark, in my opinion normal users should most often not be enabled to delete rows and more important also not be able to recall (undelete) them, I would have hidden that by default. Many other defaults also are a matter of taste, some might prefer gridlines only horizontal, others only vertical, for most black is a bit too strong for the lines, this could have been a medium grey, at least there is GridLinesColor.

Anyway, keep it as it works.

Bye, Olaf.
 
Thanks Olaf,
I've applied your comments about the textbox and column. Yeah, it's a bit non-intuitive from my perspective how much power the Column has overall, so now that I've gone to a lot of default it's cleaner and smoother, so thanks for that advise. I'm now working on my second implementation. So far it's working good. I have the icons appearing as I want them, just a few touches on some memo field writing, nothing to do with the grid itself. Very nice outcome. The grid is I think, the steepest learning curve in all of VFP. But now that I'm getting it "tamed", it's proving very useful.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Notice you may know the grid better than you think:

Code:
USE ?
BROWSE NAME oBrowse NOWAIT 
? oBrowse.Class

So a browse window is a host to nothing else but a grid.

You can also learn from borwse configurations how grids will have the same binding and more.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top