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

AutoGenerateColumns from ObservableCollection

1 Answer 17 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 13 Dec 2013, 01:21 AM
I have a situation where I need to base the grid on an observable collection and I want to auto generate the columns based on the values of the Period property of the collection. For example, given the following code I want the column headers to display 2013, 2014, 2015, etc.

Imports System.Collections.ObjectModel
 
Class MainWindow
 
    Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dim colSubjects As New ObservableCollection(Of Subject)
 
        colSubjects.Add(New Subject With {.Period = 2013, .Subject = "English", .Average = 1.65})
        colSubjects.Add(New Subject With {.Period = 2014, .Subject = "English", .Average = 18.6})
        colSubjects.Add(New Subject With {.Period = 2015, .Subject = "English", .Average = 15.4})
        colSubjects.Add(New Subject With {.Period = 2016, .Subject = "English", .Average = 8.2})
        colSubjects.Add(New Subject With {.Period = 2017, .Subject = "English", .Average = 9.72})
        colSubjects.Add(New Subject With {.Period = 2018, .Subject = "English", .Average = 8.55})
 
        colSubjects.Add(New Subject With {.Period = 2013, .Subject = "Mathematics", .Average = 1.65})
        colSubjects.Add(New Subject With {.Period = 2014, .Subject = "Mathematics", .Average = 18.6})
        colSubjects.Add(New Subject With {.Period = 2015, .Subject = "Mathematics", .Average = 15.4})
        colSubjects.Add(New Subject With {.Period = 2016, .Subject = "Mathematics", .Average = 8.2})
        colSubjects.Add(New Subject With {.Period = 2017, .Subject = "Mathematics", .Average = 9.72})
        colSubjects.Add(New Subject With {.Period = 2018, .Subject = "Mathematics", .Average = 8.55})
 
        colSubjects.Add(New Subject With {.Period = 2013, .Subject = "Biology", .Average = 1.65})
        colSubjects.Add(New Subject With {.Period = 2014, .Subject = "Biology", .Average = 18.6})
        colSubjects.Add(New Subject With {.Period = 2015, .Subject = "Biology", .Average = 15.4})
        colSubjects.Add(New Subject With {.Period = 2016, .Subject = "Biology", .Average = 8.2})
        colSubjects.Add(New Subject With {.Period = 2017, .Subject = "Biology", .Average = 9.72})
        colSubjects.Add(New Subject With {.Period = 2018, .Subject = "Biology", .Average = 8.55})
 
        gvRigs.ItemsSource = colSubjects
    End Sub
 
    Private Class Subject
        Public Subject As String
        Public Period As Integer
        Public Average As Single
    End Class
End Class

Does anyone have any suggestions?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 14 Dec 2013, 03:33 PM
Hi,

RadGridView does not provide such an option. You will have to organize your data, so that to have property for each year. That way RadGridView will generate the respective columns.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or