Results 1 to 2 of 2

Thread: WPF DataGrid refuses to AutoGenerateColumns somehow...

  1. #1
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1213

    WPF DataGrid refuses to AutoGenerateColumns somehow...

    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:

    Code:
    <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:



    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?

  2. #2
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1213
    Gaaah nevermind just figured it out... For future reference, the DataGrid only creates columns for public properties, it does nothing for public fields.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •