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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use DataTemplate in GridDataControl?

Thread ID:





102976 Mar 19,2012 09:34 PM UTC Apr 18,2012 12:45 PM UTC WPF 5
Tags: GridControl
Andrew Rosenblum
Asked On March 19, 2012 09:34 PM UTC

How is a DataTemplate applied in a GridDataControl? Is there an example?

In my requirement, the xaml does not contain VisibleColumns. All data and columns are created by binding observable data to the grid's ItemsSource.

The data template is

GridDataControl contains DataTemplate parameter, but setting as follows has no affect:

Is this a bug? How can data defined by binding be formatted?

Rajasekar [Syncfusion]
Replied On March 20, 2012 01:22 PM UTC

Hi Andrew,

Sorry for the inconvenience, We have tested the reported issue in different scenario but we are unable to reproduce the issue. It is wokring fine from our side. Could you please check the below sample?

Sample: http://www.syncfusion.com/downloads/Support/DirectTrac/88378/SyncfusionGDC-1217144405.zip

We suspect you are using our grid in some other scenario, So If possible could you please modify our sample and revert us with replication procedure, that would be very helpful to resolve your problem earlier.

Please let know if you have any queries.


Andrew Rosenblum
Replied On March 21, 2012 12:53 PM UTC

Attached is an example based on ObservableCollectionDemo_2010.sln

The data of interest displayed in the grid is of type NoDecimalNumber and TwoDecimalNumber. They are rendered by ToString(). Rows and columns are transposed so a column will contain both types.

I would like to specify the visual formatting (like the StringFormat and right justification) in the xaml code. this work.

How would DataTemplate be used for this? Or could a different xaml attribute be used for the same purpose?

Observable Collection Demo_347e08b7.zip

Andrew Rosenblum
Replied On March 21, 2012 12:57 PM UTC

To be clear, ToString should not be used like it is in the example. I would prefer to specify the format string from the xaml. Would also like to specify font and right justify from xaml.

Andrew Rosenblum
Replied On March 21, 2012 09:05 PM UTC

Can someone at Syncfusion take a look? Do I need to open a ticket?

Rajasekar [Syncfusion]
Replied On April 18, 2012 12:45 PM UTC

HI Andrew,

Sorry for the delay in getting back to you.

1.You cannot apply string formats in the XAML.
2.You can apply horizontal alignment to the DataTemplate cell by using the below code,

this.grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
e.Style.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;

3.The above same similar code should be used for applying Fonts to the DataTemplate cell.

Please let us know if you have any queries.



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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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