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

MVVM - Add one Column Dynamically in RadGridView

1 Answer 224 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Padmaja
Top achievements
Rank 1
Padmaja asked on 26 Jan 2015, 09:49 PM
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.










1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 29 Jan 2015, 04:07 PM
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.

 
Tags
General Discussions
Asked by
Padmaja
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or