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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get CellValue inside sfDataGrid_ToolTipOpening event method ?

Thread ID:

Created:

Updated:

Platform:

Replies:

141284 Dec 4,2018 10:03 AM UTC Dec 10,2018 07:15 AM UTC WinForms 5
loading
Tags: SfDataGrid
Cosyspro
Asked On December 4, 2018 10:03 AM UTC

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 

Deivaselvan Y [Syncfusion]
Replied On 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 


Cosyspro
Replied On 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 ? 

Deivaselvan Y [Syncfusion]
Replied On 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 


Cosyspro
Replied On 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.


Jayaleshwari N [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon