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

Truncate Text In Grid Cell

I have an SFDataGrid that is automatically populated:

<Grid:SfDataGrid Name="DataGrid" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4" Grid.RowSpan="2" Margin="10,10,10,0" ColumnSizer="SizeToHeader"
                         AutoGenerateColumns="True" ItemsSource="{Binding Positions}"
                         Background="#FF131313" Foreground="#FF1F46AE" AlternatingRowStyle="{StaticResource alternatingRowStyle}" AlternationCount="2" AllowResizingColumns="True" AllowDraggingColumns="True"
                         CellStyle="{StaticResource customCellStyle}"  FontSize="8">
                <Grid:SfDataGrid.DataContext>
                    <local:ScreensDataGridViewModel/>
                </Grid:SfDataGrid.DataContext>
            </Grid:SfDataGrid>

The text in each cell is wrapped, which causes the row height to change.  I wish to have it so that if the text does not fit within the cell it is truncated and therefore row height is always static.



7 Replies

JG Jai Ganesh S Syncfusion Team November 11, 2016 09:52 AM UTC

 
Hi David, 
 
You can achieve your requirement for increase the height of the row based on the cell value by using QueryRowHeight event, 
UG Link: 
 
Regards, 
Jai Ganesh S 



DH David Harvey November 11, 2016 01:41 PM UTC

Sadly this is the opposite of what I want.  What you suggest will either increase the row height (which I want to avoid), or force me to micro manage each row's height based on the content of every cell in that row.

All I wish to do is truncate the text if it does not fit in the cell (avoid text wrapping).

I.e. if the cell is able to fit 20 characters, and the string is 30 characters long, the string will be truncated to be 20 characters long.




JG Jai Ganesh S Syncfusion Team November 14, 2016 08:39 AM UTC

Hi David, 
 
You can achieve your requirement for truncate the text if the text not fit in the cell by setting the TextWrapping as NoWrap for columns, 
 
<syncfusion:GridTextColumn MappingName="Name" TextWrapping="NoWrap" /> 
 
Regards, 
Jai Ganesh S 



DH David Harvey replied to Jai Ganesh S November 14, 2016 08:13 PM UTC

Hi David, 
 
You can achieve your requirement for truncate the text if the text not fit in the cell by setting the TextWrapping as NoWrap for columns, 
 
<syncfusion:GridTextColumn MappingName="Name" TextWrapping="NoWrap" /> 
 
Regards, 
Jai Ganesh S 


Hello,

Thank you for getting back to me.

I'm not sure the suggestion you made will work when I am using AutoGenerateColumns="True' (as I do not know the names of the columns).

I tried to set it programmatically in C# on the DataGrid.Columns[0] object, but it does not have a TextWrapping field.

Any other suggestions?

Thank you.


JG Jai Ganesh S Syncfusion Team November 15, 2016 06:36 AM UTC

Hi David,  
  
Your requirement can be achieved by using the AutoGeneratingColumn event like below, 
  
this.sfGrid.AutoGeneratingColumn += SfGrid_AutoGeneratingColumn; 
 
private void SfGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) 
{ 
    if (e.Column.MappingName == "Name") 
        (e.Column as GridTextColumn).TextWrapping = TextWrapping.NoWrap; 
} 
  
 
Regards,  
Jai Ganesh S  



DH David Harvey November 15, 2016 03:08 PM UTC

Sweet, that works.  I was expecting more of just a generic tag that auto applies everywhere but this works good enough.

Thank you.


JG Jai Ganesh S Syncfusion Team November 16, 2016 05:45 AM UTC

Hi David, 

 

Thank you for the update. 

 

Please let us know if you need further assistance on this. 

 

Regards, 

Jai Ganesh S 



SIGN IN To post a reply.
Loader.
Up arrow icon