Show Image in Jiwa Grid  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Show Image in Jiwa Grid

Postby SBarnes » Tue Dec 01, 2020 8:34 am

How can you show an image in a column in the Jiwa Grid?

More specifically I am looking to do something similar to the the list maintenance found viewtopic.php?f=27&t=498 but where one of the database fields would be a blob/image.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Show Image in Jiwa Grid

Postby nsbandara » Tue Dec 01, 2020 5:11 pm

Hi,

Please check JiwaFinancials.Jiwa.JiwaImageUI.Images form. JiwaGrid supports FarPoint Image Cell type and you should be able to read image as byte array from database and display in grid.

http://helpcentral.componentone.com/Net ... ecell.html
User avatar
nsbandara
Occasional Contributor
Occasional Contributor
 
Posts: 43
Joined: Tue Jul 16, 2013 5:02 pm
Location: Sri Lanka
Topics Solved: 11

Re: Show Image in Jiwa Grid  Topic is solved

Postby Mike.Sheen » Tue Dec 01, 2020 6:21 pm

Exactly what Nishantha said - but to pick out the relevant bits :

Add column to grid:
Code: Select all
grdLines.AddColumn("Image", new FarPoint.Win.Spread.CellType.ImageCellType(), "Image", 20, false, true, true, true);


Handle lookup button to select an image from file system:
Code: Select all
private void grdLines_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
{
   FarPoint.Win.Spread.Column column = grdLines.ActiveSheet.Columns[e.Column];
   string RecID = grdLines.get_GridText("RecID", e.Row).ToString();
   bool isNew = (RecID == null || RecID.Trim().Length == 0);

   if (column.Tag.ToString() == "Bin")
   {
      if (RecID.Trim().Length > 0)
      {
         BusinessLogic.Remove(BusinessLogic[RecID]);
      }
      
   }
   else if (column.Tag.ToString() == "ImageLookup")
   {
      JiwaFinancials.Jiwa.JiwaApplication.Image.Image image = null;

      if (isNew)
      {                   
         string[] files = BrowseForImageFiles(true);

         if (files != null)
         {
            foreach (string filename in files)
            {
               image = Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Image.Image>();
               image.ImageBinary = System.IO.File.ReadAllBytes(filename);
               image.Name = System.IO.Path.GetFileNameWithoutExtension(filename);
               BusinessLogic.Add(image);
            }
         }
      }
      else
      {
         image = BusinessLogic[RecID];
         string[] files = BrowseForImageFiles(false);
         if (files != null)
         {
            image.ImageBinary = System.IO.File.ReadAllBytes(files[0]); ;
         }
      }

      
   }
}

public string[] BrowseForImageFiles(bool MultiSelect)
{
   System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog
   {
      Title = "Select Image",
      Filter = @"All Files (*.*)|*.*|All Pictures (bmp,gif,jpg,png,wmf)|*.bmp;*.gif;*.jpg;*.png;*.wmf|Bitmaps (*.bmp,*.dib)|*.bmp;*.dib|GIF Images (*.gif)|*.gif|JPEG Images (*.jpg)|*.jpg|PNG Images (*.png)|*.png|Metafiles (*.wmf)|*.wmf",
      Multiselect = MultiSelect,
      InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
   };

   if (openFileDialog.ShowDialog(this.Form) == System.Windows.Forms.DialogResult.OK)
   {
      return openFileDialog.FileNames;
   }

   return null;
}


Display of image in row (typically in the "displayLine" routine):
Code: Select all
 grdLines.set_GridText("Image", Row, item.ImageBinary);
 grdLines.ActiveSheet.Rows[Row].Height = grdLines.ActiveSheet.Rows[Row].GetPreferredHeight();


At the business logic side, the ImageBinary referred to in the above UI code is simply a property of type byte array.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Show Image in Jiwa Grid

Postby SBarnes » Thu Dec 17, 2020 5:55 pm

Hi Mike

how can I get the image column wide changing the width percentage makes no difference?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Show Image in Jiwa Grid

Postby Mike.Sheen » Thu Dec 17, 2020 8:04 pm

SBarnes wrote:how can I get the image column wide changing the width percentage makes no difference?


If you take a look at the documentation Nishantha linked to, you'll see a property of the ImageCellType called Style - you can set that to one of these values:
  • FarPoint.Win.RenderStyle.Normal
  • FarPoint.Win.RenderStyle.Stretch
  • FarPoint.Win.RenderStyle.StretchAndScale
  • FarPoint.Win.RenderStyle.Tile

I think you might want either Stretch or StretchAndScale - StretchAndScale will only be of use if the RowHeight of the row changes as well - so to utilise that you might need to hook into the column resize event and resize the RowHeight if the image column is resized.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Show Image in Jiwa Grid

Postby SBarnes » Fri Dec 18, 2020 7:53 am

OK thanks I'll have a look at that.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Show Image in Jiwa Grid

Postby SBarnes » Fri Dec 18, 2020 10:45 am

Ok so the answer for everyone's benefit is use Stretch and scale and then when loading the image you need to do something like this

Code: Select all

                 float pheight = grid.ActiveSheet.Rows[i].GetPreferredHeight();
                if (pheight > 500)
                {
                    pheight = 500;
                }

                grid.ActiveSheet.Rows[i].Height = pheight;

                float pwidth = grid.ActiveSheet.Columns["Image"].GetPreferredWidth();
                if (pwidth > 500)
                {
                    pwidth = 500;
                }

            grid.ActiveSheet.Columns["Image"].Width = pwidth;
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 5 guests