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.

Multi-line text cells with controlled formatting?

Thread ID:

Created:

Updated:

Platform:

Replies:

120241 Sep 13,2015 10:57 PM Sep 16,2015 02:27 AM Xamarin.iOS 3
loading
Tags: SfDataGrid
Michael Hoffmann
Asked On September 13, 2015 10:57 PM

Hi,

Does the sfDatagrid support multi-line text in cells? Specifically with precisely controller formatting?

As an example, if I wanted to hold something like an address in a cell:

123 Somestreet Road, Sometown, ST, ZIP, Country

I would want to display that as you normally would and address:

123 Somestreet Road
Sometown, ST, ZIP
Country

It would be incorrect to auto-format it to something like:

123 Somestreet
Road, Sometown,
ST, ZIP, Country

just to fit it into the cell. If the column isn't wide enough it would still be more correct to show:

123 Somestree...
Sometown, ST, ...
Country

Can that be done? Can I essentially do something like

Cell.Subrow[0] = "123 Somestreet Road";
Cell.Subrow[1] = "Sometown, ST, ZIP";
Cell.Subrow[2] = "Country";

or something similar for full control?

Harikrishnan N [Syncfusion]
Replied On September 14, 2015 08:27 AM

Hi Michael,

Thank you for using Syncfusion Products.

The SfDataGrid provides multi-line text support in cells and also allows you to customize the row height for any particular row(s). To customize the rowHeight in SfDataGrid you need to handle the QueryRowHeight event. Please refer the below code example.
 

this.SfGrid.QueryRowHeight += GridQueryRowHeight;

private void GridQueryRowHeight (object sender, QueryRowHeightEventArgs e)

{

            if (e.Height > 45) {

                        e.Height = 45;

                        e.Handled = true;

            } else if (e.RowIndex == 3) {

                        e.Height = 40;

                        e.Handled = true;

            }
}


For more details about customizing the row height of SfDataGrid, please refer the AutoRowHeight sample in our Demo samples.

The text inside the GridCell will be drawn continuously and cannot be directly customized like subrows of GridCell. However you can achieve your requirement by manually modifying the width of the GridColumn for the address to fill inside the GridCell as per your requirement. If you cannot decide this width before running your program, then you can customize the GridCell to add subviews inside it based on your requirement. Please refer the below code example to know about how to customize a GridCell.



GridTextColumn customColumn = new GridTextColumn();

customColumn.UserCellType = typeof(CustomGridCell);

customColumn.MappingName = "Address";
SfGrid.Columns.Add(customColumn);

public class CustomGridCell : GridCell

{

    UILabel street;

    UILabel city;


    public CustomGridCell()

    {

        this.CanRenderUnLoad = false;

        street = new UILabel();

        city = new UILabel();

        this.AddSubview(street);

        this.AddSubview(city);

    }


    protected override void UnLoad()

    {

        this.RemoveFromSuperview();

    }


    public override void LayoutSubviews()

    {

        this.street.Frame = new CGRect(0, 0, Bounds.Width, Bounds.Height / 2);

        this.city.Frame = new CGRect(0, Bounds.Height / 2, Bounds.Width, Bounds.Height / 2);

        base.LayoutSubviews();

    }


    protected override void Dispose(bool disposing)

    {

        this.street = null;

        this.city = null;

        base.Dispose(disposing);

    }
}


Like this you can customize the GridCell to have more than one UILabel inside it so that you can manually split the address into street, city, country, etc.. as per your requirements and layout it inside the GridCell from the sample. For more details about customizing the GridCell in SfDataGrid, please refer the Formatting sample in our Demo samples.

Please let us know if this helps.

Regards,
Harikrishnan


Michael Hoffmann
Replied On September 15, 2015 06:58 PM

Hello Harikrishnan!

I used the second approach with the custom grid cell and it worked perfectly right out of the box!

I can take that as template and easily modify it so I can pass in variable numbers of lines and let the custom cell calculate sizing based on that information. Some things I'll need to play with, such as how to get the font settings to pass down to the UILabels, and then also try and "break it" by seeing what happens when I pass in extremely long strings or other bad data.

Many thanks!
Mike

Harikrishnan N [Syncfusion]
Replied On September 16, 2015 02:27 AM

Hi Michael,

Thank you for your update.

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

Regards,
Harikrishnan


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.

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.

;