none
Picture in a grid

    Question

  • I have a table with a field that contains a Picture location (gotten with a GETFile()) and a field with a persons name. I can add/edit just fine and the form displays the picture for each record no problem, in a Image control.

     

    I would like to display on a new form a grid with the picture (very small 41x41) in the first column and the name of the person in the second. I have tried droping the image control onto column1 and setting control source to the image. I can't change the image because it is a field. The image control does'nt accept a field as a file name or even a control source. 

     

    This question has most likely been ask many times, but, I have not seen an answer that works.

    I'm using VFP 6.0 if it makes any differance. If your able to answer this question please be sure to not leave out any steps or details.

     

    Thanks much!

     

     

    Tuesday, December 02, 2008 5:21 PM

Answers

All replies

  • Hi Eyon!

    I don't have VFP 6 so I can't test if my code works, but here's the solution in VFP 9

     

    First you should create a class based on VFP image class:

     

    Code Snippet

    Create Class MyImage of MyClassLib as Image

     

    Then using Class\New Property menu add a property called Value. remember to mark "Assign Method" check box.

    in Value_Assign method remove the commented line and paste this:

     

    Code Snippet

    this.Picture=vNewVal

     

     

    then go to your form's show method and paste these lines:

     

    Code Snippet

    set classlib to MyClassLib

    this.grid1.column1.addobject("MyImage",MyImage")

    this.grid1.column1.currentcontrol="MyImage"

    this.grid1.column1.sparse=.f.

     

     

    and run your form

    you may need to change other properties in your class to fit your needs

     

    hope that helps

    Tuesday, December 02, 2008 6:00 PM
  • Thanks for you quick responce. While I understand how to do what it is you have posted, I'm not quite how to apply it to my design.

     

    The form uses a table called (personel)

    The Grid column1 should display a picture. That picture location (filename) is stored in a field called (personel.pictureloc).

    Column 2 displays a field called (personel.name)

     

    The table (personel) contains 10-20 records the grid should display all pictures and names in the table. How do I tie this into the above code?

     

    Tuesday, December 02, 2008 6:36 PM
  • You can find a sample in this FAQ entry:

     

    http://www.universalthread.com/Report.aspx?Session=4B476F2F344750534A35593D207265367133726D4A70585835307178366E706D3836744E374436386637364B5A

     

    Basically you use one of dynamic properties and set the picture filename.

     

    PS: Picture in one column and name in other might be waste of space. You may create a container with an image + textbox(es) for name and put all in same column.

    +-----+

    |     | FirstName

    |Photo| LastName

    |     | Title

    +-----+

    Tuesday, December 02, 2008 6:54 PM
  • Thanks for the help. I believe I can use the information from the link so solve my problem. That is also a good Idea to put all the info into one column. It would save space and look better.

     

    Thanks again

    Tuesday, December 02, 2008 7:27 PM
  • If anyone is interested, I took a good look at the listing posted by CetinBasoz. The link is a prg that reads the files listed in a directory you select and displays them in a grid all done through a prg. I was able to use this and make a form using the forms designer that uses a field in a table to do the same thing. It works great. I'll post the steps.

     

    Step 1  Make a form using the forms designer and place a Grid on it. (default Grid1 is ok)

     

    Step 2  Set columncount = number of columns wanted

      Set Recordsource = (your table with the field that contains file location field)

      Set RecordType=  1 -alias

      Adjust the headers with the titles wanted

      In the columns that are text/numeric/memos setup their control sources

         (Don't do anything to the column that will hold your pictures)

      Adjust the column width and height (keep in mind the column must be big enough to fit your pictures)

         (you will notice that the height will be the same for all columns which might look strange) 

         (If it just 1 column for pictures it will look fine) I put a short description in the next column and it

         looks just fine. I adjusted the font size.

     

    Step 3  Insert the following code into Grid Init Event procedure

    Code Snippet

    thisform.grid1.columns(1).addobject('myContainer','Container')
    thisform.grid1.columns(1).CurrentControl = 'myContainer'
    thisform.grid1.columns(1).Sparse = .f.
    thisform.grid1.columns(1).myContainer.addobject('myImage','Image')
    thisform.grid1.columns(1).myContainer.myImage.Visible = .t.
    thisform.grid1.columns(1).Dynamicbackcolor = 'thisform.fake()'

    *note Columns(1) is the first column. You can substute 1 for 2,3 or whatever number represents the column where the picture it going to be placed.

     

    Step 4  Go up to the menubar select Form and then New Method Name the method fake

     

    Step 5  Under forms properities All way down at the bottom will be the method fake.

    Insert the following code

    Code Snippet

    thisform.Grid1.Columns(1).myContainer.myImage.Picture = YourTable.pictureloc
    Return thisform.Grid1.Backcolor

    Of course, YourTable.pictureloc should changed to a table name. the fieldname for the picture location field.

     

    I hope this is of use for others.

    Thanks once again to all of you that supplied answers!


    Wednesday, December 03, 2008 6:22 PM
  • Yes bas'cally what code show'ng was that you need a dynamic* property to setup image control's picture property (otherwise all rows would show the same picture).

     

    I want to point your step 3. If you are using designer then you don't need hat code:

     

    -Put a container on form (container is not a must you may directly use the imag control)

    -Put an image into that container

    -Cut the container with Ctrl+X

    -Ctrl+Click grid to put into edit mode

    -Click the desired column where photo would go

    -Paste with Ctrl+V (there is a reason we first put the control on form then cut&paste - if you needed more complex controls and or coede in this controls it is very hard to do after it goes into column)

     

    -Set column sparse to .F. and DynamicBackColor to (thisform.Fake()) in PropertiesEventsMethods sheet

     

     

    PS: If you use DynamicFontBold instead (or any other Dynamic* that needs to return a boolean you can write 'Fake' code like:

     

    thisform.Grid1.Columns(1).myContainer.myImage.Picture = YourTable.pictureloc

     

    • Proposed as answer by RichDay Monday, September 30, 2013 3:44 PM
    • Unproposed as answer by RichDay Monday, September 30, 2013 3:47 PM
    Wednesday, December 03, 2008 8:47 PM
  •  CetinBasoz is right about his post. I have also discovered the the Dynamics because they update with every record, can be used for a whole lot of other things such as generating summeries & totals and Im sure alot  things I haven't thought of.

     

    Thanks

    Sunday, December 07, 2008 5:54 PM
  • Great bit of code sorted my picture in grid.

    Thanks

     

    Thursday, July 07, 2011 2:17 PM