Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I created a
DataGrid
with binding to
DataTable
, here:
<DataGrid1:DataGrid x:Name="dg" CanUserDeleteRows="True" AutoGenerateColumns="False" ItemsSource="{Binding MyDataTable}">
<DataGrid1:DataGrid.Columns>
<DataGrid1:DataGridTemplateColumn SortMemberPath="[First Column name]" Header="First Column name">
<DataGrid1:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding [First Column name],Mode=TwoWay}" />
</DataTemplate>
</DataGrid1:DataGridTemplateColumn.CellTemplate>
</DataGrid1:DataGridTemplateColumn>
</DataGrid1:DataGrid.Columns>
</DataGrid1:DataGrid>
and when I click on header to sort the table, I get this exception :
An unhandled exception of type 'System.ArgumentException' occurred in PresentationFramework.dll
Additional information: 'My_Table_Name' type does not have property named '[First Column name]', so cannot sort data collection.
–
–
–
–
SortMemberPath
is meant to point to a string containing the property name, NOT to a binding.
You can use [FirstColumnName]
in your TextBox.Text
because it is a binding, so is binding to DataRow[FirstColumnName]
SortMemberPath
is a property name, so is trying to reference DataRow.[FirstColumnName]
, which doesn't exist.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.