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

radgridview dynamic gridviewcolumn formatting

2 Answers 236 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Loic
Top achievements
Rank 1
Loic asked on 10 Nov 2014, 07:34 AM
Hello,

I create dynamically my columns through an attached property and can't seem to set the string format for my columns. I would like my number have the format 1234.00 > 1,234.00

How to do that ?

I tried with:
in my .xaml:

<telerik:RadGridView  x:Name="RadGridView1"    
                              ItemsSource="{Binding ResultsViewModelList}" AutoGenerateColumns="False"  
                              custom:GridViewDataColumnsBehavior.BindableColumns="{Binding ColumnCollection}"
...
    
in my view model :
 // Toggle Column
GridViewToggleRowDetailsColumn gridRowToggle = new GridViewToggleRowDetailsColumn();
ColumnCollection.Add(gridRowToggle);

//data column
GridViewDataColumn column =
new GridViewDataColumn();
 string columnName = "column1";
 column.Header = columnName;
 column.UniqueName = columnName;
 column.DataMemberBinding = new Binding("ResultDataDictionary[" + columnName + "]");
 column.DataMemberBinding.StringFormat = "0:N"//also tried with N , {0:N}, ...
//also tried > column.DataFormatString = "0:N";
 column.DataType = typeof(double);
 
ColumnCollection.Add(column);

in GridViewDataColumnsBehavior:

public static readonly DependencyProperty BindableColumnsProperty =
            DependencyProperty.RegisterAttached("BindableColumns",
                                                typeof(ObservableCollection<GridViewColumn>),
                                                typeof(GridViewDataColumnsBehavior),
                                                new UIPropertyMetadata(null, BindableColumnsPropertyChanged));
 
        private static void BindableColumnsPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            RadGridView RadGridView = source as RadGridView;
            ObservableCollection<GridViewColumn> columns = e.NewValue as ObservableCollection<GridViewColumn>;
            RadGridView.Columns.Clear();
            if (columns == null)
            {
                return;
            }
            foreach (GridViewColumn column in columns)
            {
                RadGridView.Columns.Add(column);
            }
 
.....

2 Answers, 1 is accepted

Sort by
0
Loic
Top achievements
Rank 1
answered on 10 Nov 2014, 08:25 AM
How to delete the thread?
I just find out that the data that I passed is a string and not a number. That is why the formatting does not work.
0
Dimitrina
Telerik team
answered on 10 Nov 2014, 08:42 AM
Hi,

I am glad to hear you managed to resolve the issue. I would suggest you leaving this thread as it could also be useful to the community.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Loic
Top achievements
Rank 1
Answers by
Loic
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or