Sign In|Join
Home/Silverlight.NET Forums/Silverlight Controls and Silverlight Toolkit/Change the style of cell within datagrid/Re: Change the style of cell within datagrid
Member
438 Points
166 Posts
Oct 29, 2008 11:31 AM | LINK
Amanda Wang - MSFT Hi, You can try to refer the below code the change the datagrid's column 2 and row 2's font color to blue. private void peopleDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { if (e.Row.GetIndex() == 2) { this.peopleDataGrid.SelectedIndex = e.Row.GetIndex(); DataGridColumn column = this.peopleDataGrid.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; cell.Foreground = new SolidColorBrush(Colors.Blue); } } } private FrameworkElement GetParent(FrameworkElement child, Type targetType) { object parent = child.Parent; if (parent != null) { if (parent.GetType() == targetType) { return (FrameworkElement)parent; } else { return GetParent((FrameworkElement)parent, targetType); } } return null; }
Hi,
You can try to refer the below code the change the datagrid's column 2 and row 2's font color to blue.
private void peopleDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { if (e.Row.GetIndex() == 2) { this.peopleDataGrid.SelectedIndex = e.Row.GetIndex(); DataGridColumn column = this.peopleDataGrid.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result;
cell.Foreground = new SolidColorBrush(Colors.Blue); } } }
private FrameworkElement GetParent(FrameworkElement child, Type targetType) { object parent = child.Parent; if (parent != null) { if (parent.GetType() == targetType) { return (FrameworkElement)parent; } else { return GetParent((FrameworkElement)parent, targetType); } } return null; }
very nice [:)] it helped me too. thanks Amanda Wang
mr.saif
Member
438 Points
166 Posts
Re: Change the style of cell within datagrid
Oct 29, 2008 11:31 AM | LINK
very nice [:)] it helped me too. thanks Amanda Wang
Muhammad Saifullah