【问题标题】:Add a row at a specific index of the datagrid在数据网格的特定索引处添加一行
【发布时间】:2015-07-08 10:46:56
【问题描述】:

在我的 Silverlight Datagrid 中,我得到一个汇总所有先前行中的值的总计行。我需要让用户将新行添加到网格中,但我需要在总计行之前显示它,尽管总计行已经显示在 Datagrid 中。

这就是我在 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;

空行由用户编辑以输入数据。

如何在 MyData 的特定索引处输入这样的行?

【问题讨论】:

    标签: c# silverlight datagrid


    【解决方案1】:

    您可以使用 Insert 方法而不是 Add 方法在特定索引处插入一行。

    MyData.Insert(2, myrow);
    

    您可以在以下链接中找到有关 ObservableCollection 中可用的各种方法的更多信息:https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-18
      • 2013-05-14
      • 2016-06-24
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      相关资源
      最近更新 更多