Show dataannotation Description to column header tooltip

Hi,

I have a model with data annotations, for example:

[DataMember()]

[Display(Name = "Projekt neve", Description = "Tooltip", Order = 2)]

[Required(ErrorMessage = "A mező kitöltése kötelező!")]

[StringLength(60, ErrorMessage = "Maximum {1} karakter hosszú lehet!")]

public string? Megnevezes { get; set; }


With these settings the grid sets the column name and order well, but it not show the Description part as the column header tooltip.

Can you help me please how can I solve this problem?

Thank you!

BR, SZL


5 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team August 19, 2022 01:50 PM UTC

Hi SZL,

SfDataGrid Does not contain direct support to set the column header tooltip with DataAnnotation. Currently, we are checking the feasibilities to achieve your requirement. We need two more business days to validate this. We will update you with further details on August 23, 2022.

We appreciate your patience until then.


Regards,

Dhanasekar M.



DM Dhanasekar Mohanraj Syncfusion Team August 23, 2022 03:48 PM UTC

Hi SZL,


Still, we are checking the feasibilities to achieve your requirement. We will check and update you with further details on August 25, 2022.


We appreciate your patience and understanding.


Regards,

Dhanasekar M.



DM Dhanasekar Mohanraj Syncfusion Team August 25, 2022 02:50 PM UTC

Hi SZL,


You can achieve your requirement to Set the Description attribute content to the tooltip message using the tooltip opening event shown below,

private void SfDataGrid1_ToolTipOpening(object sender, Syncfusion.WinForms.DataGrid.Events.ToolTipOpeningEventArgs e)

{

    var record = (this.sfDataGrid1.View.Records[0].Data as OrderInfo).GetType().GetProperty(e.Column.MappingName);

    var propertyInfo = record.GetCustomAttributes(true);       

    if (e.RowIndex == 0)

    {

        if (propertyInfo == null || propertyInfo.Length == 0 || (propertyInfo[0] as DisplayAttribute).Description == null)

            return;

 

        e.ToolTipInfo.Items[0].Text = (record.GetCustomAttributes(true)[0] as DisplayAttribute).Description;

    }

}


Here we have prepared a sample based on your requirement. Please find the sample in the attachment and let us know if you have any concerns about this.

Regards,
Dhanasekar M.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDatagridDemo_4390bb19.zip

Marked as answer

SZ SZL replied to Dhanasekar Mohanraj August 27, 2022 06:01 PM UTC

Hy,

Thank you for help! Based on your example I succeed to show the tooltip.

BR, SZL



DM Dhanasekar Mohanraj Syncfusion Team August 29, 2022 02:52 PM UTC

Hi SZL,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you.

Regards,
Dhanasekar M.


Loader.
Up arrow icon