MVVM - Add one Column Dynamically in RadGridView

2 posts, 0 answers
  1. Padmaja
    Padmaja avatar
    1 posts
    Member since:
    Sep 2014

    Posted 26 Jan 2015 Link to this post

    Hi,

    My application is in MVVM. I have a RadGridview where 2 columns are Databound and I have to generate third column dynamically with RowNumbers.
    Here is my code. I am getting (collection) in the third column. The other 2 columns are fine. Please help me on this. 

    XAML:

    <telerik:RadGridView  Name="TestGridView"  ItemsSource="{Binding TestListView}" AutoGenerateColumns="False">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewColumn Header="RowCount">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <StackPanel>
                                                <TextBlock Text="{Binding TestRowNumber}"  />
                                            </StackPanel>
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                </telerik:GridViewColumn>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName}" Header="NetBIOS Name" />
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Salary}" Header="Model" />
         </telerik:RadGridView.Columns>
                        </telerik:RadGridView>

    ViewModel:

    public void Testupdate()
            {
                RadObservableCollection<int> rno = new RadObservableCollection<int>();
                for (int i = 1; i <= TestList.Count; i++)
                {
                    rno.Add(i);      
                 }  
              TestRowNumber= rno;
             } 

      private RadObservableCollection<int> _testRowNumber;
            public RadObservableCollection<int> TestRowNumber
            {
                get { return _testRowNumber; }
                set
                {
                    _testRowNumber = value;
                 
                    OnPropertyChanged();
                }
            }

    Its showing correct count in the rno with items 1 to 6. But when displaying on the grid, its showing (collection). I am not able to trace where I am going wrong. Please correct me.

    Thank you.










  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 29 Jan 2015 Link to this post

    Hi Padmaja,

    In your case you are getting a collection in your third column because its bound to a collection on the business object level. A possible way to go about this is define the property from your business object as a simple integer. In addition you can check our RowNumber WPF / Silverlight demo which demonstrates how you can make such a column.

    I hope this helps.

    Regards,
    Boris
    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top