radgridview dynamic gridviewcolumn formatting

3 posts, 0 answers
  1. Loic
    Loic avatar
    7 posts
    Member since:
    May 2014

    Posted 10 Nov 2014 Link to this post

    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. Loic
    Loic avatar
    7 posts
    Member since:
    May 2014

    Posted 10 Nov 2014 Link to this post

    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.
  3. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Nov 2014 Link to this post

    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.

     
Back to Top