Page 1 of 1

Show Image in Jiwa Grid

PostPosted: Tue Dec 01, 2020 8:34 am
by SBarnes
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.

Re: Show Image in Jiwa Grid

PostPosted: Tue Dec 01, 2020 5:11 pm
by nsbandara
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

Re: Show Image in Jiwa Grid  Topic is solved

PostPosted: Tue Dec 01, 2020 6:21 pm
by Mike.Sheen
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.

Re: Show Image in Jiwa Grid

PostPosted: Thu Dec 17, 2020 5:55 pm
by SBarnes
Hi Mike

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

Re: Show Image in Jiwa Grid

PostPosted: Thu Dec 17, 2020 8:04 pm
by Mike.Sheen
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.

Re: Show Image in Jiwa Grid

PostPosted: Fri Dec 18, 2020 7:53 am
by SBarnes
OK thanks I'll have a look at that.

Re: Show Image in Jiwa Grid

PostPosted: Fri Dec 18, 2020 10:45 am
by SBarnes
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;