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

Truncate Text In Grid Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

127369 Nov 10,2016 12:43 PM UTC Nov 16,2016 05:45 AM UTC UWP 7
loading
Tags: SfDataGrid
David Harvey
Asked On November 10, 2016 12:43 PM UTC

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.



Jai Ganesh S [Syncfusion]
Replied On 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 


David Harvey
Replied On 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.



Jai Ganesh S [Syncfusion]
Replied On 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 


David Harvey
Replied On 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.

Jai Ganesh S [Syncfusion]
Replied On 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  


David Harvey
Replied On 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.

Jai Ganesh S [Syncfusion]
Replied On 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 

CONFIRMATION

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.

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

;