Customer formatting using QueryCellInfo

I am using the DataGrid and trying to do some custom grid formatting using the QueryCellInfoCommand.  I get the style object out in the callback, but I need the object from the bound item source (because i determine the style from that).  How can i get this object using the cellStyle?  Thanks.

1 Reply

RS Ravi Shankar B Syncfusion Team November 29, 2012 07:28 AM UTC

Hi John,

 

We have analyzed your query and you can achieve your requirement by get the record through CellIdentity from GridDataStyleInfo as follows.

C# code snippet:

 void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)

        {

            var style = e.Style as GridDataStyleInfo;

            var cellidentity = style.CellIdentity;

            if (cellidentity != null && cellidentity.Record != null)

            {

                //Here based on the cellidentity.Record, you can apply style

 

                var Record = cellidentity.Record as DataRowView;

                var item =Record.Row.ItemArray[3];

                if (item.ToString().Contains("Mobile"))

                    e.Style.Background = Brushes.Lavender;

            }

        }

 

Alternatively, for your requirement we have Conditional Formatting feature, you can format the cell style by cell values as follows.

 

XAML code snippet:

 <syncfusion:GridDataControl.ConditionalFormats>
                <syncfusion:GridDataConditionalFormat Name="Column1" ApplyStyleToColumn="ProductPrice">
                    <syncfusion:GridDataConditionalFormat.Style>
                        <syncfusion:GridDataStyleInfo Background="BurlyWood" />
                    </syncfusion:GridDataConditionalFormat.Style>
                    <syncfusion:GridDataConditionalFormat.Conditions>
                        <syncfusion:GridDataCondition ColumnName="ProductPrice"
                                                      ConditionType="GreaterThan"
                                                      PredicateType="And"
                                                      Value="200" />
                    </syncfusion:GridDataConditionalFormat.Conditions>
                </syncfusion:GridDataConditionalFormat>
            </syncfusion:GridDataControl.ConditionalFormats>

 

 

We have created simple sample on this and you can download the sample from the following link.

http://www.syncfusion.com/downloads/Support/DirectTrac/101303/GDC_CustomFromatting-1610974018.zip

 

Regards,

Ravi Shankar B.


Loader.
Up arrow icon