【wpf-grid】獲取當前所在行數,根據指定值行給grid設置背景色

獲取當前所在行數

             //獲取當前所在行數
            int rowIndexE = 0;
            var _cells = MyDataGrid.SelectedCells;
            if (_cells.Any())
            {
                rowIndexE = MyDataGrid.Items.IndexOf(_cells.First().Item);
            }

根據指定值行給grid設置背景色

 if (vmodel.BatchNoDetail.batchNo != null && vmodel.BatchNoDetailList.Count > 0)
            {
                for (int i = 0; i < MyGrid.Items.Count; i++)
                {
                    if (vmodel.BatchNoDetail.batchNo.Equals(vmodel.BatchNoDetailList[i].batchNo))
                    {
                        // vmodel.BatchNoDetailList[i].RowByBatchNoForeGround = "Red";
                        DataGridRow row = (DataGridRow)this.MyGrid.ItemContainerGenerator.ContainerFromIndex(i);
                        if (row != null) {
                            row.Background = Brushes.Red;
                        }
                    }

                }

            }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章