ResizeToFit in grid with multiline text

HI,
I have GGC which contain record with field "Description".
This is a multiline text field.
How to automaticaly set rows height in this grid to show all text.

I found this:
https://www.syncfusion.com/kb/5042/how-to-resizetofit-a-cell-with-multi-line-text-in-gridgroupingcontrol

It is working, but problem I have where scroll records by mouse wheel.
It looks like grid have problem with refresh.
Page Up and Page Down keys working good.

Any ideas ?
I see problem is when last row is part viewed

13 Replies

AR Arulpriya Ramalingam Syncfusion Team January 29, 2018 05:27 PM UTC

Hi Krzysztof, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed the reported scenario at our end. The QueryRowHeight event will be triggered whenever the height for the rows are changed and the height for the rows which not in visible range will be returned as zero. So, that the reported issue occurred when the rows are moved to visible range. The range can be invalidated to avoid the paint issue on scrolling. We have modified the sample as per your scenario. Please make use of the below code and sample, 
 
Code example 
 
//this event gets triggered when the row height is changed. 
void TableModel_QueryRowHeight(object sender, GridRowColSizeEventArgs e) 
{ 
    if (e.Index > 0) 
    { 
        IGraphicsProvider graphicsProvider = this.gridGroupingControl1.TableModel.GetGraphicsProvider(); 
        Graphics g = graphicsProvider.Graphics; 
        GridStyleInfo style = this.gridGroupingControl1.TableModel[e.Index, 2]; 
        GridCellModelBase model = style.CellModel; 
        e.Size = model.CalculatePreferredCellSize(g, e.Index, 2, style, GridQueryBounds.Height).Height; 
        e.Handled = true; 
    } 
    //To avoid the painting issue 
    this.gridGroupingControl1.TableControl.InvalidateRange(GridRangeInfo.Table()); 
} 
 
 
Please let us know, if you have any other queries. 
 
Regards, 
Arulpriya 



KA Krzysztof Adamowicz January 29, 2018 08:17 PM UTC

Hi,
after adding line
this.ContactGrid.TableControl.InvalidateRange(GridRangeInfo.Table());
I have two problems:
1) On another control (TPanel) on the form Label is partailly freshed
Panel have Dock atribut Botto and Grid have Dock attribut Fill.
2) Dramaticly decrease performance, I have about 100 records




AR Arulpriya Ramalingam Syncfusion Team January 30, 2018 07:51 PM UTC

Hi Krzysztof, 
 
Thanks for your update. 
 
We have analyzed all the possibilities to meet your requirement at our end. Since, the Style and graphics are retrieved for each cell in the provided solution, the reported issue occurred. In order to ResizeToFit the row heights based on the cell value when multiple lines are added in the cell, the GridEngineFactory class before invoking the InitializeComponent method and can use the ResizeToFit() method to fit the height. We have modified the sample as per your requirement. Please refer to the below code and sample, 
 
Code example 
 
//To enable the individual height for rows 
GridEngineFactory.Factory = new AllowResizingIndividualRows(); 
InitializeComponent(); 
//data binding 
this.gridGroupingControl1.DataSource = ReturnATable(); 
//the size set evenly according to the content of cells. 
this.gridGroupingControl1.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table()); 
//Event triggering 
this.gridGroupingControl1.TableControlCurrentCellEditingComplete += GridGroupingControl1_TableControlCurrentCellEditingComplete; 
 
//Event customization 
private void GridGroupingControl1_TableControlCurrentCellEditingComplete(object sender, GridTableControlEventArgs e) 
{ 
    //T resize the height after the cell value is updated. 
    this.gridGroupingControl1.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table()); 
} 
 
 
 
Please let us know, if you need further assistance on this. 
 
Regards, 
Arulpriya 



KA Krzysztof Adamowicz February 26, 2018 08:18 PM UTC

Looks better.
I'm testing now.


AR Arulpriya Ramalingam Syncfusion Team February 27, 2018 05:22 AM UTC

Hi Krzysztof, 
 
Thanks for your update. 

We are glad to hear that the provided solution was resolved your scenario.   
 
Please let us know, if you have any other queries. 
 
Regards, 
Arulpriya 



KA Krzysztof Adamowicz February 27, 2018 10:20 PM UTC

One question.
I add 
            GridEngineFactory.Factory = new AllowResizingIndividualRows();
at the beginning.
In Shown method I fill grid from database after that I put
            ContactGrid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table());
After runnig application height of row is too big 3,4 times
But when I refresh grid (again fill and ResizeToFit) from that moment working fine.

Where is the best place to put ResizeToFit ??
In example is CurrentCellEditingComplete but not working because my grid is only for show edit is disabled.


AR Arulpriya Ramalingam Syncfusion Team February 28, 2018 12:58 PM UTC

Hi Krzysztof, 
 
Thanks for your update. 
 
To update the row height based on the cell content, the ResizeToFit() method should be called whenever the cell value is updated. As per your use case (i.e. resize the height on initializing), we would suggest you to use the ResizeToFit() method when the cell value is updated (i.e. after initializing the grid with cell contents). The ResizeToFit() method with multiline is working fine at our end and please refer to the below screenshot and sample, 
 
Screenshot 
 
 
 
Note 
Ensure that the WrapText property for the grid is enabled to resize the row height. Moreover, provide your exact requirement with simple screenshot/video, if we misunderstood your scenario. 
 
Regards, 
Arulpriya 



KA Krzysztof Adamowicz February 28, 2018 10:00 PM UTC

I'm still have problem.
I'm trying 
        private void ContactGrid_TableControlCurrentCellEditingComplete(object sender, GridTableControlEventArgs e)
        {
            ContactGrid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table());
        }
But still the same.
It's looks like when the window appear frst time, height is the same for all rows and is calculated from the biggest row.
When I run
            ContactGrid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table());
second time, from this moment is fine.

Maybe it matters that i have second GridGroupingControl on this form without multiple text ?








AR Arulpriya Ramalingam Syncfusion Team March 1, 2018 11:57 AM UTC

Hi Krzysztof,   
   
Thanks for your update.   
   
By default, the ResizeToFit() will measures the height of the string in each cell and calculates the maximum height of the strings to set the default row height based on the content of cell value. We suspect that the reported use case might occurred due to the customization of grid (i.e. enabling theme for grid after setting the resize to fit for the rows). So, we would suggest you to, use the ResizeToFit method after performing all the grid settings and define the data source for grid. Moreover, ensure that the DefaultRowHeight of the grid is reset after calling the ResizeToFit() also the grid with non-multiline does not affect the ResizeToFit() method of another grid. If possible, provide the call stack of RowHeights changing event after the rows are resized based on cell contents from the provided sample.   
   
Code example   
   
//the size set evenly according to the content of cells.   
this.gridGroupingControl1.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table());   
   
//Event triggering   
this.gridGroupingControl1.TableModel.RowHeightsChanging += newGridRowColSizeChangingEventHandler(TableModel_RowHeightsChanging);   
   
//Event handling   
void TableModel_RowHeightsChanging(object sender,GridRowColSizeChangingEventArgs e)   
{   
    //Provide us the stack trace/Call stack.   
}   
   
Regards,   
Arulpriya  



KA Krzysztof Adamowicz March 1, 2018 09:03 PM UTC

Hi,
added code
        void TableModel_RowHeightsChanging(object sender, GridRowColSizeChangingEventArgs e)
        {
            //Provide us the stack trace/Call stack.   
            string path = @"c:\temp\RowHeightsChanging.txt";
            using (StreamWriter sw = File.AppendText(path))
            {
                sw.WriteLine("Time:" + DateTime.Now.ToString());
                sw.WriteLine("Cancel:" + e.Cancel);
                sw.WriteLine("From:"+e.From);
                sw.WriteLine("To:" + e.To);
                sw.Write("Values:");
                for (int i = 0; i < e.Values.Length; i++)
                    sw.Write(e.Values[i].ToString() + ",");
                sw.WriteLine();
            }
        }
And output in attachement
This method was invoke 3 times
1) ResiseToFit in Shown method
2) First visit in grid, strange is that most rows have height 58 (two rows)
3) After refresh its fine






Attachment: RowHeightsChanging_ebe2c88.7z


AR Arulpriya Ramalingam Syncfusion Team March 2, 2018 12:58 PM UTC

Hi Krzysztof, 
 
Thanks for your update. 
 
We have created a new support-incident for the reported query under your account and updated the details in the incident. We request you to follow-up with that incident for better follow-up. 

 
Regards, 
Arulpriya R.  



KA Krzysztof Adamowicz March 2, 2018 08:53 PM UTC

I dont't know why, but when I change WrapText to false in AnyCell ... it is working.
  <Appearance>
    <AnyCell>
      <WrapText>false</WrapText>
    </AnyCell>
  </Appearance>

Thanx


AR Arulpriya Ramalingam Syncfusion Team March 5, 2018 08:47 AM UTC

Hi Krzysztof, 
 
Thanks for your update. 

We are glad to hear that the reported scenario was resolved at your end. 
 
Please let us know, if you have any other queries. 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon