problem with GridImageColumn

Good morning all:

I'm having a problem getting an image to populate the GridImageColumn in the DataGrid.  The code below is what I'm using, I can confirm that the image is saved to the application local location in HoldImages folder and is named ImageHold.png.  I can also see that ImageDisplay class has the Uri loaded as the image uri source and that that the class is the itemsource for DisplayGrid.  It all looks like it should work, however when it goes to print it throws a "value cannot be null" error, it does not indicate what value is null.  

john


System.ArgumentNullException occurred
  HResult=0x80004003
  Message=Value cannot be null.
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at Syncfusion.UI.Xaml.Grid.PrintManagerBase..ctor(ICollectionViewAdv view)
   at Syncfusion.UI.Xaml.Grid.SfDataGrid.Print()
   at Estimation_And_Design.Controls.ReportUserControl.<AddImageAsync>d__8.MoveNext() in C:\Users\johnw\documents\visual studio 2017\Projects\Estimation And Design\Estimation And Design\Controls\ReportUserControl.xaml.cs:line 94





  

    public ObservableCollection<ImageLinkModel> ImgCollection = new ObservableCollection<ImageLinkModel>();
    public ObservableCollection<WriteableBitmap> ImageCollection = new ObservableCollection<WriteableBitmap>();

    public class ImageLinkModel
    {
        public BitmapImage ImageDisplay { get; set; }
    }

        public async void AddImageAsync()
        {
            int ImageIndex = 1;
            foreach (WriteableBitmap item in ImageCollection)
            {
                // First save the image to local, replace if it exits
                await SaveBitmapToFileAsync(item, "ImageHold" + ImageIndex.ToString() + ".png");

                // Use the saved image to populate the class
                ImageLinkModel ILM = new ImageLinkModel();
                ILM.ImageDisplay = new BitmapImage(new Uri(string.Format("ms-appdata:///local/HoldImages/ImageHold" + ImageIndex.ToString() + ".png"), UriKind.Absolute));
                ImgCollection.Add(ILM);
                ImageIndex = ImageIndex + 1;
            }

                // Class added as image source
                DetailGrid.ItemsSource = ImgCollection;

                // Create the column
                this.DetailGrid.Columns.Add(new GridImageColumn() { HeaderText = "Design", MappingName = "ImageDisplay", Stretch = Stretch.Uniform });

               // Print the grid
                DetailGrid.PrintSettings = new PrintSettings();
                DetailGrid.PrintSettings.AllowColumnWidthFitToPrintPage = true;
                DetailGrid.Print();
 
        }




4 Replies

SJ Sathiyathanam Jeyakumar Syncfusion Team January 2, 2018 12:35 PM UTC

Hi John,

Thank you for contacting Syncfusion support.

 
 On analyzing with the given code snippet, we have found that you have invoked to print the grid control before creating the view and it causes the exception issue. You can resolve this issue by invoke the print method once after the grid loaded into the “SfDataGrid.Loaded” event as like below code snippet. You can modify your application with the below code snippet and let us know if this helps you. 
 
this.DetailGrid.Loaded += DetailGrid_Loaded; 
 
private void DetailGrid_Loaded(object sender, RoutedEventArgs e) 
{ 
    if (DetailGrid.View != null) 
    { 
      DetailGrid.Print(); 
    } 
} 

Please let us know if you have any other questions.

Regards,
Sathiyathanam 



JW john warns January 2, 2018 01:44 PM UTC

The event never fires, which is strange I would expect it to fire at some point.  Also when you look at DataGrid just before the error you see "Columns = Count = 1" so there is something loaded it is not null.

john


JW john warns January 2, 2018 03:07 PM UTC

Ok I've gotten it to work.  This code is contained in a User Control.  Even thought that control was instantiated (ReportUserControl RUC = new ReportUserConttol();) it doesn't seem to actually be available.  The fix was to force the user control to be the child of a grid on the page (PrintData.Children.Add(RUC);).


John



GT Gnanasownthari Thirugnanam Syncfusion Team January 3, 2018 06:56 AM UTC

Hi John, 

Thank you for your update, 

Please let us know if you need further assistance on this. 

Regards, 
Gnanasownthari T. 


Loader.
Up arrow icon