Summary Row Text Truncated (Last few charachters)

1 Answer 30 Views
GridView
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Shubham asked on 13 Oct 2023, 10:21 AM

Hi,
Actually we have made Custom Summary Item for displaying helper text. But we are facing one issue we are displaying helper text in a summary row but that text got truncated from last (i.e. last few characters are missing when displayed).Please have look on below image to have good understanding of issue.
I am providing you the code which we have used. If you need any more information. Please let me know

Code:

Method to set summary row text

                

 private void SetHelpText(string strHelpText)
        {
            if (this.SummaryRowsTop.Count == 0)
            {
                CustomSummaryStatusItem summaryItem = new CustomSummaryStatusItem(this.MasterTemplate.Columns[0].Name, strHelpText + "", GridAggregateFunction.Count);
                GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
                // Used to set cell value in GrdData_ViewCellFormatting
                summaryItem.Name = "StatusText|" + strHelpText;

                summaryRowItem.Add(summaryItem);
                this.SummaryRowsTop.Add(summaryRowItem);
            }
            else
            {
                var summaryRowTop = this.SummaryRowsTop[0];
                var summaryItem = summaryRowTop[0] as GridViewSummaryItem;
                summaryItem.Name = "StatusText|" + strHelpText;
            }

            var summaryRowIndex = this.MasterView.SummaryRows.IndexOf(this.SummaryRowsTop[0]);
            this.MasterView.SummaryRows[summaryRowIndex].PinPosition = PinnedRowPosition.Top;
            this.MasterView.SummaryRows[summaryRowIndex].IsVisible = true;

            this.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Bottom;
            this.MasterTemplate.BottomPinnedRowsMode = GridViewBottomPinnedRowsMode.Fixed;
        }

 

Custom Summary Item:

public class CustomSummaryStatusItem : GridViewSummaryItem
    {
        public CustomSummaryStatusItem(string name, string formatString, GridAggregateFunction aggregate)
        : base(name, formatString, aggregate)
        { }
        public override object Evaluate(IHierarchicalRow row)
        {
            return 1;
        }
    }

Below Attached Image will help you to know more about issue. Please have a look on them.
Actual Text Dispalyed


Expected Text To Display
Thanks,
Shubham Jain

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 16 Oct 2023, 09:05 AM

Hi Shubham,

Thank you for the provided code snippet.

I am assuming that in the ViewCellFormatting event, the GridSummaryCellElement cell MinSize property is set to extend the cell to see the full text. To get the correct value, we could measure the text.  To that, I have used the Graphics.MeasureString as described in this KB article. However, after doing this, the text is still not fully visible. You will need to add a few more pixels due to some space at the begging and at the end of the cell.

private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridSummaryCellElement)
    {
        if (!string.IsNullOrEmpty(e.CellElement.Value.ToString()))
        {
            Graphics gp = Graphics.FromHwnd(this.Handle);
            var textSize = gp.MeasureString(e.CellElement.Value.ToString(), e.CellElement.Font);
            e.CellElement.MinSize = new Size((int)textSize.Width+ 10, 0);
        }
    }
}

After this, the text is fully visible.

Can you try this approach and let me know if this approach works for you?

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 19 Oct 2023, 08:50 AM

Hi Dinko,

Actually I am setting summary row text on the click event of search grid because I need to change the text based on column selected in search grid. I have two grids  search grid and data grid search grid is top one. check below image for better clarity.

so the above approach will not work from me.
please help me.

Thanks,
Shubham Jain

Dinko | Tech Support Engineer
Telerik team
commented on 19 Oct 2023, 01:16 PM

Upon trying to reproduce this behavior on my side, I am not sure I was able to fully follow your approach. If I have correctly understood your case, clicking on the first grid (Search Grid) changes the text in the summary row of the second grid (Data Grid). In my test project, the text was changed successfully. Check the following GIF file from my project:

Can you check the attached project and let me know what I need to modify to mimic your implementation and reproduce this behavior?

As a side note, I noticed that the Name property of the SummaryItem is change to :   summaryItem.Name = "StatusText|" + strHelpText; Keep in mind that the Name property points to the column name. Changing the Name to the following string "StatusText|" + strHelpText could lead to an empty row as there could not be a column name with this same combination. I am not saying that this is wrong, there could be a column with the same string in your application, however, you can double-check if setting the Name property is required.

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 20 Oct 2023, 06:17 AM | edited

Hi Dinko,
I checked your attached project it was working fine in that for me what is happening that my code never goes inside second if block: I.e.  below condition always getting false not sure why the sting is empty in all case. and because of this i think it is not working for me.
!string.IsNullOrEmpty(e.CellElement.Value.ToString())


if (e.CellElement is GridSummaryCellElement) { if (!string.IsNullOrEmpty(e.CellElement.Value.ToString())) { Graphics gp = Graphics.FromHwnd(this.Handle); var textSize = gp.MeasureString(e.CellElement.Value.ToString(), e.CellElement.Font); e.CellElement.MinSize = new Size((int)textSize.Width+ 10, 0); } }

 

 

Thnaks,
Shubham Jain
Dinko | Tech Support Engineer
Telerik team
commented on 20 Oct 2023, 01:46 PM

Using only the provided code snippet, I can only guess why is not working in your application. What comes to my mind is to double-check if you have subscribed to the correct grid ViewCellFormatting event. If this is not the case, may I ask you to modify my project and add your code so that I can take a closer look and debug it on my side?

I am looking forward to your reply.

Tags
GridView
Asked by
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or