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

Bind RadGridView to List(Of MyObject)

2 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 08 Jun 2011, 06:35 PM
Hi, I'm trying to bind a RadGridView to a List(Of MyObject) where MyObject is a class with properties. When I set the ItemsSource on the Grid to my list, a row does get created however none of the data is in it. It doesn't look like it is getting to the properties in my object in order to display their values in the columns.

Grid:
<telerik:RadGridView x:Name="RadGridView1" Margin="0"
                             RowIndicatorVisibility="Collapsed" IsReadOnly="True" 
                             Width="750" MinHeight="100" MaxHeight="200"
                             AutoGenerateColumns="True" CanUserFreezeColumns="False" 
                             CanUserResizeColumns="False"
                             Grid.Row="1">
              
            <telerik:RadGridView.Columns>
                <telerik:GridViewImageColumn Header="Actual Encounters" DataMemberBinding="{Binding ActualEncounters}" />
                <telerik:GridViewDataColumn Header="Peer Encounters" DataMemberBinding="{Binding PeerEncounters}" />
                <telerik:GridViewDataColumn Header="Actual Cost/Episode" DataMemberBinding="{Binding ActualCostPerEpisode}" />
                <telerik:GridViewDataColumn Header="Peer Cost/Episode" DataMemberBinding="{Binding PeerCostPerEpisode}" />
                <telerik:GridViewDataColumn Header="Cost/Episode Index" DataMemberBinding="{Binding CostPerEpisodeIndex}" />
                <telerik:GridViewDataColumn Header="Actual Total Cost" DataMemberBinding="{Binding ActualTotalCost}" />
            </telerik:RadGridView.Columns>
              
        </telerik:RadGridView>

Binding:
Private Sub GetCostAndUtilizationSummaryMeasuresForServiceCategoryCallback(ByVal sender As Object, ByVal e As ProviderService.GetCostAndUtilizationSummaryMeasuresForServiceCategoryCompletedEventArgs)
    Dim lRecord As Dictionary(Of String, String) = e.Result
    Dim lDatalist As New List(Of CostAndUtilizationSummaryMeasuresData)
    lDatalist.Add(New CostAndUtilizationSummaryMeasuresData(lRecord("ServiceCategory"),
                        lRecord("ActualEncounters"),
                        lRecord("PeerEncounters"),
                        lRecord("ActualCostPerEpisode"),
                        lRecord("PeerCostPerEpisode"),
                        lRecord("CostPerEpisodeIndex"),
                        lRecord("ActualTotalCost")))
    Dim lModelList As New List(Of CostAndUtilizationSummaryMeasuresDataViewModel)
    For Each lDataItem As CostAndUtilizationSummaryMeasuresData In lDatalist
        lModelList.Add(New CostAndUtilizationSummaryMeasuresDataViewModel(lDataItem))
    Next
    RadGridView1.ItemsSource = Nothing
    RadGridView1.ItemsSource = lModelList
End Sub

CostAndUtilizationSummaryMeasuresData:

Public Class CostAndUtilizationSummaryMeasuresData
  
    Private ServiceCategory As String 
    Private ActualEncounters As Integer 
    Private PeerEncounters As Integer
    Private ActualCostPerEpisode As Decimal 
    Private PeerCostPerEpisode As Decimal 
    Private CostPerEpisodeIndex As Decimal 
    Private ActualTotalCost As Decimal 
  
    Public Sub New(ByVal pServiceCategory As String
        ByVal pActualEncounters As Integer
        ByVal pPeerEncounters As Integer, _
        ByVal pActualCostPerEpisode As Decimal, _
        ByVal pPeerCostPerEpisode As Decimal, _
        ByVal pCostPerEpisodeIndex As Decimal, _
        ByVal pActualTotalCost As Decimal)
  
        ServiceCategory = pServiceCategory
        ActualEncounters = pActualEncounters
        PeerEncounters = pPeerEncounters 
        ActualCostPerEpisode = pActualCostPerEpisode 
        PeerCostPerEpisode = pPeerCostPerEpisode 
        CostPerEpisodeIndex = pCostPerEpisodeIndex 
        ActualTotalCost = pActualTotalCost 
  
    End Sub
  
End Class

CostAndUtilizationSummaryMeasuresDataViewModel:

Public Class CostAndUtilizationSummaryMeasuresDataViewModel
  
    Private _data As CostAndUtilizationSummaryMeasuresData
  
    Public Sub New(data As CostAndUtilizationSummaryMeasuresData)
        Me._data = data
    End Sub
  
    Public ReadOnly Property Data() As CostAndUtilizationSummaryMeasuresData
        Get
            Return _data
        End Get
    End Property
  
End Class

The data IS being returned from the service, it just looks like the grid doesn't know how to associate the columns with the properties in my class.

Thank you in advance for any advice or help!

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 09 Jun 2011, 06:33 AM
Hi,

 You do not have any properties for your object - just fields. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jfkrueger
Top achievements
Rank 1
answered on 09 Jun 2011, 06:02 PM
Lol wow, can't believe I did that. Boy do I feel dumb! Haha thank you!
Tags
GridView
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
Vlad
Telerik team
jfkrueger
Top achievements
Rank 1
Share this question
or