wpf datagrid 遍歷行


如果 DataGrid 中的行還未被加載,即 LoadingRow 事件未發生,那么針對此行的 GetCellContent() 是不可能得到東西的,只能為 null。

 下面兩種語法,只是變相的形式而已。

    for (int i = 0; i < dgETL.Items.Count; i++)
            {
                CheckBox selectCheckBoxInCell = dgETL.Columns[0].GetCellContent(dgETL.Items[i]) as CheckBox;
                if (selectCheckBoxInCell != null)
                {
                    selectCheckBoxInCell.IsChecked = cbxOne.IsChecked;
                }
            }

            foreach (var item in dgETL.Items)
            {
                CheckBox selectCheckBoxInCell = dgETL.Columns[0].GetCellContent(item) as CheckBox;
                if (selectCheckBoxInCell != null)
                {
                    selectCheckBoxInCell.IsChecked = cbxOne.IsChecked;
                }
            }

 GridViewRow s = ((GridViewRow)PSFileDataGrid.ItemContainerGenerator.ContainerFromIndex(1));
            if (s != null)
            {
                Button sb = null;
                GridViewCellBase j =
                      (from c in s.Cells where c.Column.Name == "uid" select c).FirstOrDefault();
                if (j != null)
                {
                    sb = j.Template.FindName("button1", j) as Button;
                    sb.IsEnabled = false;
                }

            }


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM