Hi there,
I need some help!
I'm iterating through, adding in new rows to an already rendered XamDataGrid. While I add in these new rows, I need to get access to each cell's Cell Value Presenter or its Editor. I know I can use the use the Cell object's Value property, but I'm using a custom editor, so I need access to the CVP or Editor to set my custom editor's value property. The way I understand it, these elements won't be created until the XamDataGrid has a chance to initialize the new record.
If I try to retrieve the CVP when I create the DataRecord, it comes back null. Is there an event I can tie to to get the CVP?
foreach (string line in lineParsedText)
{
object newItem = (myGrid.DataSource as IBindingList).AddNew();
Type objType = newItem.GetType();
DataRecord newRecord = (myGrid.Records. Last() as DataRecord);
IEnumerator cellParsedText = line.Split(delimiters, StringSplitOptions.None).GetEnumerator();
foreach (Cell myCell in newRecord.Cells)
PropertyInfo property = objType.GetProperties().FirstOrDefault(x => x.Name.Equals(myCell.Field.Name));
if (!cellParsedText.MoveNext())
break;
if (!property.CanWrite)
continue;
var assignmentDelegate = new EventHandler<Infragistics.Windows.DataPresenter.Events.InitializeCellValuePresenterEventArgs>(delegate(object propertyChangedSender, Infragistics.Windows.DataPresenter.Events.InitializeCellValuePresenterEventArgs propertyChangedEventArgs)
if (myCell != null && propertyChangedEventArgs.CellValuePresenter == CellValuePresenter.FromCell(myCell))
CellValuePresenter cvp = CellValuePresenter.FromCell(myCell);
if (cvp != null && cvp.Editor != null)
ValueEditor editor = cvp.Editor;
XamNumericEditor customEditor = editor.Template.FindName("XamNumericEditorWrapper", editor) as XamNumericEditor;
if (customEditor != null)
customEditor.Text = displayText;
return;
}
editor.Text = displayText;
});
myGrid.InitializeCellValuePresenter += assignmentDelegate;
Thanks to anyone that can help!
Sorry, I misunderstood what you were saying in your last post. I tried using the eventManager.. .but that didn't help either.
The problem is, I put a breakpoint in the delegate, and it never gets fired - the same thing happened when I tried to subscribe to a grid's InitializeCellValuePresenterEvent manually.
here's my code:
var assignmentDelegate = new EventHandler<InitializeCellValuePresenterEventArgs>(delegate(object delegateSender, Infragistics.Windows.DataPresenter.Events.InitializeCellValuePresenterEventArgs delegateArgs)
if (CellValuePresenter.FromCell(myCell) == delegateArgs.CellValuePresenter)
SetDisplayValue(myCell, ObjectToString(cellParsedText.Current));
EventManager.RegisterClassHandler(typeof(XamDataGrid), XamDataGrid.InitializeCellValuePresenterEvent, assignmentDelegate);
Your initial post was referring to the CellValuePresenter and not the DataRecordPresenter. Moreover, you will be looking for an element inside the CVP and not DRP, so you probably need the CVP - ensure that you will find what you are looking for.
Maybe I'm misunderstanding, but doesn't the DataRecordPresenter also only get created after initialization, not as soon as I create a DataRecord? Perhaps some sample code would help show me how to do this
Probably, you can hook up directly to the Loaded event of the CellValuePresenter of the DataRecordPresenter. You can do that for example with the EventManager.RegisterClassHandler(...) method or with Style (and EventSetter). This way you will have the Presenter loaded and ready to be traversed in search of the custom editor.