sfDataGrid1 Bind a Tableau Adding text and images, it was found to be blank.

is . demo

 DataTable dt = new DataTable();

 public Form2()
 {
     InitializeComponent();

     dt.Columns.Add("name", typeof(string));
     dt.Columns.Add("img", typeof(Image));

     sfDataGrid1.AutoGenerateColumns = false;
     sfDataGrid1.DataSource = dt;

     sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "name", HeaderText = "name" });
     sfDataGrid1.Columns.Add(new GridImageColumn() { MappingName = "img", HeaderText = "img" });

 }

 private void button1_Click(object sender, EventArgs e)
 {
     dt.Rows.Add("demo", pictureBox1.Image);
 }


Image_2563_1728460668023

Attachment: WindowsFormsApp6_e179361c.7z


3 Replies

SP Sreemon Premkumar Muthukrishnan Syncfusion Team October 10, 2024 03:51 PM UTC

Hi yu ma,


Currently, the SfDataGrid does not support loading images as the Image type. To load an image into the cell of the GridImageColumn, you need to convert the image to a Byte[] array type. Please find the code snippet and the user guide documentation below for the details of the implementation.

Code Snippet:

 public byte[] ImageToByteArray(System.Drawing.Image imageIn)

 {

     MemoryStream ms = new MemoryStream();

     imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

     return ms.ToArray();

 }


Loading images:

 var image1 = Image.FromFile(@"..\..\Images\Demo1.jpg");

 var image2 = Image.FromFile(@"..\..\Images\Demo2.jpg");

 var imageBitArray1 = ImageToByteArray(image1);

 var imageBitArray2 = ImageToByteArray(image2);

 dt.Rows.Add("demo1", imageBitArray1);

 dt.Rows.Add("demo2", imageBitArray2);


UG Link:Column types in WinForms DataGrid control | Syncfusion

We have prepared a sample to address your requirement. Please find it in the attachment.

We have analyzed and considered this as the requirement “Provide support for Loading Images as Image Type in GridImageColumn of SfDataGrid” and logged feature request for the same. We will implement this feature in any of our upcoming release.

At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.

Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.

We will provide the feedback for the feature request by tomorrow.

We appreciate your patience until then.


Regards,
Sreemon Premkumar M.


Attachment: WinForms_SfDataGrid_c85a358b.zip


YM yu ma replied to Sreemon Premkumar Muthukrishnan October 11, 2024 06:35 AM UTC

hi  Sreemon Premkumar Muthukrishnan


I know how to insert images into arrays, but in terms of convenience, images are more convenient


thank



SP Sreemon Premkumar Muthukrishnan Syncfusion Team October 11, 2024 05:39 PM UTC

Hi yu ma,


Thanks for the update, but currently, the SfDataGrid does not support loading images as the Image type. We have analyzed and considered this as the requirement “Support to load images as Image Type in GridImageColumn of DataGrid” and logged feature request for the same. We will implement this feature in any of our upcoming release.

At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.

Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.

Feedback link: Support to load images as Image Type in GridImageColumn of DataGrid in WinForms | Feedback Portal (syncfusion.com)

If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count.


Regards,
Sreemon Premkumar M.


Loader.
Up arrow icon