【问题标题】:WPF Datagrid row Index always is 0WPF Datagrid 行索引始终为 0
【发布时间】:2015-04-16 17:57:23
【问题描述】:

我正在尝试获取当前编辑行索引,但它会一直返回 0,我认为是因为网格还没有可视化,所以我创建了一个调度程序来运行代码,但仍然无法正常工作

以下是我的代码

private void grdUser_RowEditingEnd(object sender, DataGridRowEditEndingEventArgs e )
{
        Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
        {                
            int currentRowIndex = this.grdUser.ItemContainerGenerator.IndexFromContainer(this.grdUser.ItemContainerGenerator.ContainerFromItem(this.grdUser.CurrentItem));
            MessageBox.Show(currentRowIndex.ToString());

        }));
}

这是获取已编辑行索引的其他方式吗?

【问题讨论】:

    标签: c# wpf wpf-controls wpfdatagrid


    【解决方案1】:

    您可以使用 eventargs 并使用它可以获得索引。您可以参考以下代码。

    private void grdUser_RowEditingEnd(object sender, DataGridRowEditEndingEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
            {
                int currentRowIndex = this.grdUser.ItemContainerGenerator.IndexFromContainer(e.Row);
                MessageBox.Show(currentRowIndex.ToString());
    
            }));            
        }
    

    【讨论】:

      猜你喜欢
      • 2013-07-30
      • 1970-01-01
      • 2016-03-13
      • 2016-09-22
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多