Hello.
I'm using DataGrid to edit and display a list of my objects as ItemsSource, List<TimeSegment>, and my object looks like this:
public class TimeSegment
{
public DateTime StartTime
public DateTime EndTime
public TimeSpan Span
{
get
{
return this.EndTime - this.StartTime;
}
}
}
}
The Span property is calculated.
But the Span column did not update automatically, after I edit the StartTime or EndTime in DataGrid. And I want to sort the list after editing too.
I have a work around about this, but it dose not solve this gracefully.
Here is my work around, first I set a flag in the RowEditEnding event, then I ClearBinding for ItemsSourceProperty , sort the list and rebind the property in the CurrentCellChanged event after checking the flag.
My first question is
"Is there a better way to do this?".
If I have to use this work around, then I got another problem.
I want to do some logic after the List<TimeSegment> changed. It works fine after editing, but not with deleting row(s).
My second question is
"How can I do with deleting row(s)?".
I tried putting the logic in the event handler of Executed of DataGrid.DeleteCommand, but this will override the default action of DataGrid, the row did not deleted, my logic get executed.
<DataGrid.CommandBindings>
<CommandBinding Command="DataGrid.DeleteCommand"
Executed="CommandBinding_Executed" />
</DataGrid.CommandBindings>
Can somebody help me? Thanks in advance.