We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to get CellValue inside sfDataGrid_ToolTipOpening event method ?

Hello,
I want to get Cell Value in sfDataGrid_ToolTipOpening event method. I need of this cell value to convert it from Byte[] type to Image type and so display it in ToolTip.
Best regards 

5 Replies

DY Deivaselvan Y Syncfusion Team December 5, 2018 08:58 AM UTC

Hi Cosyspro, 

Thanks for contacting Syncfusion Support. 

We have created a sample to achieve your requirement to convert the Byte[] type value to image and display it in the tooltip using ToolTipOpening event. Please refer the following code example and sample from the given location. 

Code example

this.sfDataGrid1.ToolTipOpening += sfDataGrid1_ToolTipOpening; 

void sfDataGrid1_ToolTipOpening(object sender, ToolTipOpeningEventArgs e) 
{ 
    if (e.Column.MappingName == "Country" && e.Record != null) 
    { 
        var byteArray = (e.Record as OrderInfo).Country; 
 
        if (byteArray != null) 
        { 
            using (System.IO.MemoryStream stream = new MemoryStream(byteArray)) 
            { 
                e.ToolTipInfo.Items[0].Text = string.Empty; 
                e.ToolTipInfo.Items[0].Image = new Bitmap(Image.FromStream(stream)); 
            } 
        } 
    } 
} 


In the above given code example we have casted the ToolTipOpeningEventArgs.Record property to OrderInfo to get the value of a specific column in the record. If the DataGrid is bounded with a DataTable we should use DataRowView to cast the Record.  


Regards,
Deivaselvan 



CO Cosyspro December 6, 2018 09:54 AM UTC

Thanks for your response.
I want generalize sfDataGrid_ToolTipOpening for any data collection loaded in SFDataGrid. So, is it possible to get the cell value from SfDataGrid's cell by using Column type (GridImageColumn) and row index and this without use Record type ? 


DY Deivaselvan Y Syncfusion Team December 7, 2018 05:18 AM UTC

Hi Cosyspro, 

Thanks for your update. 

Please make use of the following code example and sample from the given link to get the cell value within the ToolTipOpening event in a generic way for all type of data source. 

Code example :  

this.sfDataGrid1.ToolTipOpening += sfDataGrid1_ToolTipOpening; 
 
void sfDataGrid1_ToolTipOpening(object sender, ToolTipOpeningEventArgs e) 
{ 
    if (e.Column.GetType() == typeof(GridImageColumn) && e.Record != null) 
    { 
        ItemPropertiesProvider provider = this.sfDataGrid1.View.GetPropertyAccessProvider(); 
        var byteArray = (byte[])provider.GetValue(e.Record, e.Column.MappingName); 
        if (byteArray != null) 
        { 
            using (System.IO.MemoryStream stream = new MemoryStream(byteArray)) 
            { 
                e.ToolTipInfo.Items[0].Text = string.Empty; 
                e.ToolTipInfo.Items[0].Image = new Bitmap(Image.FromStream(stream)); 
            } 
        } 
    } 
} 



Regards,
Deivaselvan 



CO Cosyspro December 9, 2018 08:21 AM UTC

Hi Deivaselvan,
Thanks for your response. It's work fine.
However, the display of the image in tooltip is limited in width. So, the display is truncated.
Regards.



JN Jayaleshwari N Syncfusion Team December 10, 2018 07:15 AM UTC

Hi Cosyspro, 
 
Thanks for the update.  
 
We have checked the query regarding “Image is truncated in tooltip’ from our side. You can resolve this by fit the image into the size of the tooltip by using Padding property of the ToolTipItem.  
 
Code snippet C#: Refer to below code, sets the padding for tooltip item. 
 
this.sfDataGrid1.ToolTipOpening += sfDataGrid1_ToolTipOpening; 
 
void sfDataGrid1_ToolTipOpening(object sender, ToolTipOpeningEventArgs e) 
{ 
    if (e.Column.GetType() == typeof(GridImageColumn) && e.Record != null) 
    { 
        ItemPropertiesProvider provider = this.sfDataGrid1.View.GetPropertyAccessProvider(); 
        var byteArray = (byte[])provider.GetValue(e.Record, e.Column.MappingName); 
        if (byteArray != null) 
        { 
            using (System.IO.MemoryStream stream = new MemoryStream(byteArray)) 
            { 
                e.ToolTipInfo.Items[0].Text = string.Empty; 
                e.ToolTipInfo.Items[0].Image = new Bitmap(Image.FromStream(stream)); 
                e.ToolTipInfo.Items[0].Padding = new Padding(0); 
            } 
        } 
    } 
} 
 
We have attached the sample for your reference and you can download the same from the following location. 
 
Please let us know if you would require further assistance. 
 
Regards, 
Jayaleshwari N 


Loader.
Live Chat Icon For mobile
Up arrow icon