Hi, I want to highlight a cell or a row in my datagrid (Bold and Blue). Either of them (hightlighting a cell or the entier row) will work for me. I need to iterate thru rows, check on values of some columns and make that row hightlighted.
Can you please tell me how to do this?
Thanks
Hello,
This exception is raised because of the virtualization techniques of the XamDataGrid. Any records that are out of view will not have DataRecordPresenters generated for them. This is why you are getting Null Reference Exception. What you can go is use the RecordsInViewChanged event and iterate only though them. They will all have DataRecordPresenters. You can get the records that are currently in view with the GetRecordInView(...) method.
The other (not recommended approach) is to change the virtualization - set the RecordContainerGenerationMode to PreLoad. This way, DataRecordPresenters will be generated for all of the records. However, if you have a lot of records, this will have performance impact and memory overhead.
I tried the following but I am getting null for DataRecordPresenter drp.
foreach (Record r in datagrid.Records)
{
string field1 = ((Infragistics.Windows.DataPresenter.DataRecord)(r)).Cells["field1"].Value.ToString();
string field2 = ((Infragistics.Windows.DataPresenter.DataRecord)(r)).Cells["field2"].Value.ToString();
if (String.IsNullOrEmpty(field1) && String.IsNullOrEmpty(field2))
DataRecordPresenter drp = DataRecordPresenter.FromRecord(r) as DataRecordPresenter;
r.DataPresenter.FontWeight = FontWeights.Bold;
r.DataPresenter.Foreground = Brushes.Blue;
}