Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting Columns of type decimal? (nullable) in WPF DataGrid
    primarykey
    data
    text
    <p>I am working with a <code>DataGrid</code> in WPF with several <code>decimal</code> columns. I recently changed the bound properties to <code>decimal?</code>s and now these columns are not able to be sorted by clicking on the header (as my other columns are). However, I can still sort them using methods in my code-behind. Does anybody know if it's possible to sort the <code>decimal?</code> columns by clicking the header or what the reason behind it is if it's not possible? Here is my relevant code:</p> <p>A couple of the columns in question (The attribute attaches to a behavior for the DataGrid. Enabling/disabling the behavior makes no difference):</p> <pre><code>[Column("PPAvg", 7)] public decimal? ProjectedPointsAvg { get; set; } [Column("PPHi", 8)] public decimal? ProjectedPointsHi { get; set; } [Column("PPLo", 9)] public decimal? ProjectedPointsLo { get; set; } </code></pre> <p>The DataGrid itself:</p> <pre><code>&lt;DataGrid x:Name="poolDataGrid" Grid.Row="1" CanUserAddRows="False" IsReadOnly="True" MouseDoubleClick="poolDataGrid_MouseDoubleClick"&gt; &lt;i:Interaction.Behaviors&gt; &lt;local:ColumnHeaderBehavior /&gt; &lt;/i:Interaction.Behaviors&gt; &lt;/DataGrid&gt; </code></pre> <p>I can still sort via code-behind using something like this:</p> <pre><code>var col = poolDataGrid.Columns.SingleOrDefault(c =&gt; c is DataGridTextColumn &amp;&amp; c.Header.ToString() == "PPHi"); poolDataGrid.Items.SortDescriptions.Add(new SortDescription(col.SortMemberPath, ListSortDirection.Descending)); </code></pre> <p>Unfortunately, I don't have much else to add. If anybody could help me out with this I would greatly appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload