I'm attempting to bind a lookup table to a grid on a WPF form, using this as a guide. The form displays with column headings but no data. However there are 73 rows of blank data. There should be 73 rows of actual data.
This lookup table is an entity class:
Partial Public Class tlkpProcedures_PartB
Public Property CPT As String
Public Property ProcedureName As String
Public Property BillingAmount As Nullable(Of Decimal)
Public Property UniqueID As Integer
'Public Overridable Property tblBilling_PartB As ObservableCollection(Of tblBilling_PartB) = New ObservableCollection(Of tblBilling_PartB)Notice that I commented out the last line. This was automatically generated code but since I don't care about related billing data at this point, it was commented out. I'm not sure this is even relevant to my problem.
I created an observable collection of this class:
Public Class PartBProcedures
Inherits ObservableCollection(Of tlkpProcedures_PartB)
Public Sub New()
If _conn.State = ConnectionState.Closed Then
_conn.Open()
End If
_cmd = New SqlCommand()
_cmd.Connection = _conn
Dim sSQL As String = "SELECT " & _"tlkpProcedures_PartB.CPT, " & _"ISNULL(tlkpProcedures_PartB.ProcedureName, '') AS ProcedureName, " & _"ISNULL(tlkpProcedures_PartB.BillingAmount, 0) AS BillingAmount, " & _"tlkpProcedures_PartB.UniqueID " & _"FROM tlkpProcedures_PartB " & _"ORDER BY CPT"
_cmd.CommandText = sSQL
Dim Reader As SqlDataReader = _cmd.ExecuteReader()
If Reader.HasRows Then
'bolCheckDate = False
While Reader.Read()
MyBase.Add(New tlkpProcedures_PartB)
End While
End If
_conn.Close()
End SubBound this class to the grid:
<Window.Resources><local:PartBProcedures x:Key="ProcedureData"/></Window.Resources><DataGrid HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="251" Width="271"
ItemsSource="{Binding Source={StaticResource ProcedureData}}" />Results:
Thanks.