This is a migrated thread and some comments may be shown as answers.

[Solved] Gridview column - cannot get formatting to work!

2 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Peter Swaniker
Top achievements
Rank 1
Peter Swaniker asked on 08 Jan 2010, 07:07 PM

Hi,
I'm using the Q3 release of the GridView for Silverlight and for some reason I cannot get any of the formatting to work. For example in this column, I'm setting both the DataFormatString as well as a custom converter and neither of them work. The only way I can get the formatting to work is to add it to the DataLoaded event but then because the data has already been loaded, the formatting is only applied when I reload the data. How can I set the formatting in the XAML???

XAML:

<

 

telerikGrid:GridViewDataColumn IsReadOnly="True"

 

 

Header="Start" DataMemberBinding="{Binding CONTRACT_START,Converter={StaticResource dateConverter}}" DataFormatString="{}{0:d}" />

DataLoaded Event:

 

RadGridView

 

grid = (RadGridView)sender;

 

 

for (int x = 0; x < grid.Columns.Count; x++)

 

{

 

if ((((GridViewDataColumn)grid.Columns[x]).DataType == typeof(DateTime)))

 

{

 

GridViewDataColumn gvdc = (GridViewDataColumn)grid.Columns[x];

 

 

if (gvdc.DataMemberBinding.Converter == null)

 

{

gvdc.DataMemberBinding.Converter =

new DateConverter();

 

}

}

}

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Jan 2010, 07:25 AM
Hi,

Can you post an example where this can be reproduced? Everything is working fine on our demo:
http://demos.telerik.com/silverlight/#GridView/DataFormatting

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Peter Swaniker
Top achievements
Rank 1
answered on 11 Jan 2010, 05:53 PM
I found the cause of the issue. I'm using the

RadGridViewSettings

class provided in your demo app to store the grid setting and this class was removing the grid formating. In the LoadState method, the grid columns are being re-created and as your can see the dataformatstring is not included.

 

 

foreach

 

(ColumnSetting setting in Settings.ColumnSettings)

 

{

 

GridViewDataColumn column = new GridViewDataColumn();

 

column.UniqueName = setting.UniqueName;

 

column.DataMemberBinding =

new Binding(setting.PropertyName);

 

column.Header = setting.Header;

 

if (setting.Width != null)

 

{

column.Width =

new GridViewLength(1, GridViewLengthUnitType.Star);

 

 

}

grid.Columns.Add(column);

}

Tags
GridView
Asked by
Peter Swaniker
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Peter Swaniker
Top achievements
Rank 1
Share this question
or