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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

dataGrid.GetRowHeight(e.RowIndex) returns always '0'

Thread ID:





150645 Jan 14,2020 12:52 PM UTC Jan 20,2020 05:43 AM UTC Xamarin.Android 6
Tags: SfDataGrid
Frank Effenberger
Asked On January 14, 2020 12:53 PM UTC

I am using CustomCells for my SfDataGrid.

I want to Autofit the grid rows based on content  but unfortunately
always returns '0', so my Grid is "empty" when using DataGrid_QueryRowHeight

Do i have to do any special when working with CustomCells?
Please let me know if I should provide more code :)

Pradeep Kumar Balakrishnan [Syncfusion]
Replied On January 15, 2020 10:02 AM UTC

Hi Frank , 
Thank you for contacting Syncfusion support.. 
We have checked your query “How to measure row height for custom cell (Template column) in Xamarin Android.”. We don’t have support to measure datagrid custom cell because it's not possible to find out what kind of view custom cell contains. However we can define height to custom cell in sample level by overriding GetAutoHeight() method in your custom view please refer the following code snippet for reference. 
Code Snippet: 
public class CustomCell : GridCell 
    TextView textView; 
    public CustomCell(Context context) : base(context) 
        textView = new TextView(this.Context); 
        this.CanRenderUnLoad = false; 
    protected override void UnLoad() 
        if (this.Parent != null) 
            (this.Parent as VirtualizingCellsControl).RemoveView(this); 
    protected override void OnLayout(bool change, int l, int t, int r, int b) 
        this.textView.Layout(0, 0, this.Width, this.Height); 
    protected override void OnDraw(Canvas canvas) 
        this.textView.Text = DataColumn.CellValue.ToString(); 
    protected override double GetAutoHeight(object rowData) 
        string cellValue = (rowData as OrderInfo).CustomerID; 
        // return the desired value. 
        return base.GetAutoHeight(rowData); 
Please let us know if you need further assistance on this. 
Pradeep Kumar B 

Frank Effenberger
Replied On January 15, 2020 01:48 PM UTC

Hi Pradeep,
thanks for your response.

Meanwhile, I am using a DummyView with same content as the cell and calculate the max height of all cells per row. The height calculation works fine so far,
but I also encountered the next problem:

DataGrid_QueryRowHeight is not called for every row, when changing the ColumnWidth. For example my Grid has 13 items (which are all in the view), and the Event is only triggered for row 1 and row 13 (QueryRowHeightEventArgs e -> e.RowIndex). This leads to the result that only the height of row 1 and row 13 are changed.

Current Workaround:
_sfGrid.ColumnResizing += (sender, e) =>

but this leads to a bad performance

Even if I work with a normal GridTextColumn and  using

private void DataGrid_QueryRowHeight (object sender, QueryRowHeightEventArgs e)
    if (e.RowIndex != 0) {
        //Calculates and sets height of the row based on its content 
        e.Height = dataGrid.GetRowHeight(e.RowIndex);
        e.Handled = true;

the Height of the Cells is not updates correctly

Frank Effenberger
Replied On January 16, 2020 07:11 AM UTC

Sample project

I just created a simple sample project: 1000 rows, 7 items each, normal GridTextColumn

In additon to poor scrolling performance (compared to a normal recycler view) you can also see the bug mentioned.
Just drag the divider of Field01 and Field02 to the left so that the Field01-Cells needs a line break. Only the first row height ist adjusted.

(maybe 30MB upload limit is a little bit outdated :p )

Pradeep Kumar Balakrishnan [Syncfusion]
Replied On January 17, 2020 12:43 PM UTC

Hi Frank Effenberger, 
Thank you for the update. 
Query 1: “Only first and last visible row height is refreshed after resizing” 
Query row height will be raised while creating new row or updating the row in scrolling. Refresh the grid after resizing action is completed it will not lead to bad performance  
Code snippet: 
private void SfDataGrid_ColumnResizing(object sender, GridResizingEventArgs e) 
    if (e.ResizingState == ProgressStates.Completed) 
Query 2: “Bad Scrolling performance when we defined row height using QueryRowHeight” 
In your application QueryRowHeight is handled it will be raised every time new row comes to view to define row height. use the following code in QueryRowHeight handler to optimize scrolling performance. 
Code snippet: 
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) 
    // Code to skip querying of a row if already queried 
    if (e.Height != sfDataGrid.RowHeight) 
    if (e.RowIndex != 0) 
        //Calculates and sets height of the row based on its content  
        e.Height = (sender as SfDataGrid).GetRowHeight(e.RowIndex); 
        e.Handled = true; 
Please refer the following UG link to improve scrolling performance in datagrid with QueryRowHeight. 
Please let us know if you need further assistance on this. 
Delete Bin and Obj folder in projects then file size will be around 1MB. 
Pradeep Kumar B. 

Frank Effenberger
Replied On January 17, 2020 01:15 PM UTC

Thanks Pradeep, this fixed my problems so far :)

"Delete Bin and Obj folder in projects then file size will be around 1MB. "
I could have figured that out myself, sorry :p

Farjana Parveen Ayubb [Syncfusion]
Replied On January 20, 2020 05:43 AM UTC

Hi Frank , 
Thanks for the update. 
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. 
Farjana Parveen A 


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