multi-line text cell

Hello

Searching for multi-line entries in sfDataGrid on the forums, this is the only entry which is for Xamarin.iOS:

https://www.syncfusion.com/forums/120241/multi-line-text-cells-with-controlled-formatting

This post was made in 2015. Is it still valid? If so, is it applicable to Xamarin.Android?

Thanks in advance.

6 Replies

AN Ashok N Syncfusion Team December 18, 2017 11:22 AM UTC

Hi Svrz, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query and you can enter multi line text in GridColumn by setting GridColumn.LineBreakMode as WordWrap and handle the QueryRowHeight event for update the RowHeight based on the content. Please refer the below Code example: 
 
//Column Adding: 
sfGrid.Columns.Add(new GridTextColumn() { MappingName = "FirstName", 
                LineBreakMode = LineBreakMode.WordWrap }); 
 
//Event handling:  
 
sfGrid.QueryRowHeight += SfGrid_QueryRowHeight; 
 
private void SfGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) 
{ 
    if (e.RowIndex != 0) 
    { 
        // Calculates and sets the height of the row based on its content. 
        e.Height = sfGrid.GetRowHeight(e.RowIndex); 
        sfGrid.InvalidateRowHeight(e.RowIndex); 
        e.Handled = true; 
    } 
} 
 
Please refer the below UG link for more details about these two: 
 
 
 
 
Regards, 
Ashok


SV svrz December 19, 2017 05:27 PM UTC

Thank you very much, Ashok. This worked perfectly.


SV svrz December 20, 2017 12:57 AM UTC

Ashok

Another requirement is that part of the text in this multi-line entry must be colorized. I saw one of the posts on the forum regarding the coloring of the text in the grid cell and I attempted to implement the posted solution as much as possible.

The colorization requirement was met but the text entry is no longer multi-line. I made an effort to change the Textview properties in the 'GridCell' derived class in the following manner:

 public class CustomGridCell : GridCell
    {
        private TextView textview;

        public CustomGridCell(Context ctxt)
            : base(ctxt)
        {
            textview = new TextView(ctxt);
            textview.LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
            textview.SetHorizontallyScrolling(false);
            textview.SetSingleLine(false);
            textview.InputType = InputTypes.TextFlagMultiLine;
            textview.SetTextColor(Color.Black);
            CanRendererUnload = false;
            this.AddView(textview);
        }
     .
     .
     .
    //colorizing only a portion of the text via HTML tags
     protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            if (this.DataColumn != null && DataColumn.CellValue != null && textview.Text != DataColumn.CellValue.ToString())
            {
                string str = DataColumn.CellValue.ToString();

                var htmlString = Html.FromHtml(str, FromHtmlOptions.ModeLegacy);

                textview.SetText(htmlString, TextView.BufferType.Spannable);              
            }
}

Unfortunately not only the above code does not work but the height of the cells in the grid are exceedingly high.

Please advise.

Thanks very much in advance.


AN Ashok N Syncfusion Team December 20, 2017 06:02 PM UTC

Hi Svrz,  
  
Thanks for your update. We have checked your query and internally we have layout the text internally. You can achieve your requirement by customizing GridTextViewRenderer. Please refer the below code example: 
 
//Add and Remove Renderers 
sfGrid.CellRenderers.Remove("TextView"); 
sfGrid.CellRenderers.Add("TextView", new GridCellTextViewRendererExt()); 
 
//Custom renderer class: 
public class GridCellTextViewRendererExt : GridCellTextViewRenderer 
{ 
    public GridCellTextViewRendererExt() 
    { 
 
    } 
    public override void OnInitializeDisplayView(DataColumnBase dataColumn, TextView view) 
    { 
        base.OnInitializeDisplayView(dataColumn, view); 
        if (dataColumn.GridColumn.MappingName == "FirstName") 
        { 
            view.SetTextColor(Color.Red); 
        } 
    } 
       
    protected override void OnUpdateCellValue(DataColumnBase dataColumn) 
    { 
        base.OnUpdateCellValue(dataColumn); 
        if ((dataColumn as IElement).Element != null) 
        { 
            var view = (((dataColumn as IElement).Element as GridCell).GetChildAt(0) as TextView); 
            if (view != null && dataColumn.GridColumn.MappingName == "FirstName") 
            { 
                view.SetTextColor(Color.Red); 
            } 
        } 
    } 
} 
                                                 
 
Regards, 
Ashok 



SV svrz December 27, 2017 02:06 PM UTC

Thank you very much, Ashok.


AN Ashok N Syncfusion Team December 31, 2017 02:12 PM UTC

Hi Svrz,   
 
Thanks for your update, please let us know if you require further assistance on this.  
 
Regards, 
Ashok 


Loader.
Up arrow icon