0
votes

In my Silverlight Datagrid, I got a Totals row that sums up the values in all the previous rows. I need to let the user add new rows to the grid but I need it to be displayed before the Totals row, although the Totals row already is display in the Datagrid.

This is how I insert a new row in the Datagrid (QuotationDG):

  CultureInfo provider = new CultureInfo("en-US");
  Object[] myrow = new Object[QuotationDG.Columns.Count];

        for (int i = 0; i < QuotationDG.Columns.Count; i++ )
        {

            myrow[i] = Convert.ChangeType("", typeof(object), provider);

            i++;
        }
        MyData.Add(myrow); // MyData is an Observable collection of Object[]
        QuotationDG.ItemsSource = MyData;

The empty rows are edited by the user to enter data.

How can I enter such a row at a specific index of MyData ?

1

1 Answers

3
votes

You can use the Insert method instead of the Add method to insert a row at a specific index.

MyData.Insert(2, myrow);

You can find more info about the various methods available in the ObservableCollection on the following link : https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx