Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Get the CellValuePresenter or Editor for a newly created cell in a new record
posted

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!