在DataGrid中启用和禁用行

时间:2013-10-14 22:19:26

标签: c# wpf datagrid

我正在玩数据网格中的启用和禁用行:


public IEnumerable GetDataGridRows(DataGrid grid)  
{  
    var itemsSource = grid.ItemsSource as IEnumerable;  
    if (null == itemsSource) yield return null;  
    foreach (var item in itemsSource)  
    {
        var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;  
        if (null != row) yield return row;  
    }  
}  

private void DisableGridRows()
{  
    bool enableRow = false;  
    var rows = GetDataGridRows(myGrid);  
    foreach (DataGridRow dataRow in rows)  
    {  
        if (!enableRow)  
        { 
            dataRow.IsEnabled = false;  
            enableRow = true;  
        }  
        else  
        {  
            enableRow = false;  
        }  
    }  
}  

我遇到的问题是有时行不会被禁用。在调试中运行时,我无法复制问题所以它正在考虑网格没有更新的情况。

有什么想法吗?

0 个答案:

没有答案
相关问题