title: Wpf datagrid auto-increment column generating wrong values?
body: <p>Hi i am working on a simple wpf application .My issue is i want to include serial number(S_No) column which should be auto incremented but it is showing abnormal values.
  I want proper serial column as my first column.
  My code is :</p>
  
  <pre><code>public partial class MainWindow : Window
      {
          public ObservableCollection&lt;VLANS&gt; vlan { get; set; }
          public MainWindow()
          {
              InitializeComponent();
              vlan=new ObservableCollection&lt;VLANS&gt;();
              this.DataContext=this;
  
  
  
              dg.ItemsSource =vlan;
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              var serial = new VLANS();
              serial.S_No = vlan.Count;
              vlan.Add(serial);
  
              var vname = new VLANS();
              vname.VlanName = t1.Text;
              vlan.Add(vname);
  
  
  
          }
      }
  
      public class VLANS
      {
          public string VlanName { get; set; }
          public int S_No { get; set; }
      }
  }
  </code></pre>
  
  <p>XAML is:</p>
  
  <pre><code>&lt;Window x:Class="TextboxToDatagridTest.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="100"/&gt;
              &lt;RowDefinition Height="200"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;TextBox
              Name="t1"
              Grid.Row="0"
              Width="150"
              Height="50"
              Margin="200,0,0,0"
              /&gt;
          &lt;Button
              Grid.Row="0"
              Width="150"
              Height="40"
              Content="Button" FontSize="25"
              HorizontalAlignment="Left"
              Margin="80,0,0,0" Click="Button_Click"&gt;
           &lt;/Button&gt;
          &lt;DataGrid
              AutoGenerateColumns="False"
              Name="dg"
              Grid.Row="1"&gt;
              &lt;DataGrid.Columns &gt;
                  &lt;DataGridTextColumn Header="S.No" Binding="{Binding Path=S_No}" /&gt;
                  &lt;DataGridTextColumn Header="Vlan Name" Binding="{Binding Path=VlanName}"/&gt;
  
              &lt;/DataGrid.Columns&gt;
  
          &lt;/DataGrid&gt;  
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Snap is :
  <img src="https://i.stack.imgur.com/DudQ2.png" alt="enter image description here"></p>
  
  <p>Can anyone tell me where i am mistaking.
  Any help would be highly praised.</p>