I will give you two ways to generate OrderNumbers automatically.
Method1:
private void MyDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
Method2:
<Window.Resources>
<ResourceDictionary>
<local:RowToIndexConverter x:Key="rowToIndexConverter"/>
</ResourceDictionary>
</Window.Resources>
<DataGridTextColumn Header="OrderNumbers " Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource rowToIndexConverter}}" />
The converter is:
public class RowToIndexConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DataGridRow row = value as DataGridRow;
if (row != null)
return row.GetIndex() + 1;
else
return -1;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}