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.

you post your answer: 'My_Table_Name' type does not have property named '[First Column name]', so cannot sort data collection – blindmeis Dec 29, 2011 at 13:54 OMG. replace [First Column name] with First Column name.... -1 Vote for this one. Read error messages please. – GameAlchemist Dec 29, 2011 at 13:54 if you use a typed datatable it would work. i dont know wether SortMemberPath can work with indexer... – blindmeis Dec 29, 2011 at 14:02 i read this error messages more than one time.. but i dont know thet it's work without [] becouse the DataContext is DadaRow ,and also DataTable does not have property named 'First Column name'... but its working good! – Zeps Dec 29, 2011 at 14:10

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.

@Zeps You said in your question it was giving you an exception.... Using the square brackets in a binding should be fine, but using it in the SortMemberPath won't work because it's not a property name. – Rachel Dec 29, 2011 at 15:22

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.