WPF DataGrid refuses to AutoGenerateColumns somehow...

Herman

Well-known member
Joined
Oct 18, 2011
Messages
883
Location
Montreal, QC, CA
Programming Experience
10+
I have this type:
Public Class cTechSupportCall
    Public CallId As String
    Public CustomerName As String
    Public CallbackLimit As DateTime?
    Public StartTime As DateTime?
    Public StopTime As DateTime?
    Public LastModOn As DateTime?
    Public LastModBy As String
    Public Owner As String
    Public Duration As Double
End Class


And I have a Linq query that returns an IEnumerable(Of cTechSupportCall). Now I want to bind the result of that query to a WPF DataGrid. Here is the XAML for the DataGrid:

VB.NET:
<DataGrid x:Name="MyGrid" AutoGenerateColumns="True" Grid.Row="0" Margin="0" Background="White" AlternatingRowBackground="WhiteSmoke" />

When I try to bind the results of the query to the DataGrid any of the following ways:

MyGrid.ItemsSource = queryResult
MyGrid.ItemsSource = queryResult.ToList
MyGrid.ItemsSource = New ObservableCollection(Of cTechSupportCall)(queryResult)


... and then call MyGrid.UpdateLayout(), the resulting grid looks like this:

Datagrid.png


The rows of data are correctly bound, but the columns are not generated, and for the life of me I cannot figure out why... Is it the nullable DateTime that is causing this issue? This is really frustrating, because I clearly remember having no issue at all binding a datatable to a DataGrid before. Does it just not like custom types?
 
Gaaah nevermind just figured it out... For future reference, the DataGrid only creates columns for public properties, it does nothing for public fields.
 
Back
Top