How to loop over the rows of a WPF toolkit Datagrid

前端 未结 4 1057
情歌与酒
情歌与酒 2020-11-30 15:04

I have the next code where I defined a WPF toolkit datagrid control called dgQuery; I filled this one with information of a dataset, then I inserted a new checkbox column in

4条回答
  •  执笔经年
    2020-11-30 15:51

    this will return a 'row' in your datagrid

    public IEnumerable GetDataGridRows(Microsoft.Windows.Controls.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 Microsoft.Windows.Controls.DataGridRow;
                if (null != row) yield return row;
            }
        }
    

    in wpf datagrid, rows are ItemSource.items... no Rows property!

    Hope this helps...

提交回复
热议问题