Hi Guys,
I was wondering wich event fires when add/remove a column from a xamDataGrid. I'm trying to get a LabelPresenter object after a column has been added with VisualTreeHelper.GetChild(pParent, pIndex),but I'm getting the wrong object. Any idea?
Best,
Pablo
Hello Pablo,
Thank you for choosing Infragistics.
I have been looking into your issue and I have prepared a sample application for you to test and see if the desired effect is achieved.
I have created an instance of the XamDataGrid and I have bound a sample collection to its DataSource property. I have defined a Style in the XamDataGrid's resources that targets the LabelPresenter and I have created an EventSetter for the Loaded event of the LabelPresenter. This way you should be able to get and customize the LabelPresenter for each field as soon as the presenter has loaded. I have also created a button which I have used as an example to create a new Field with a BindingType property set to Unbound and add it to the initial FieldLayout's Fields collection. When the field has been successfully added, the Loaded event of the LabelPresenter is fired again and it's Background property is also set to Red.
After a field has been added to a FieldLayout's Fields collection, in order to initialize the cell values of the field for each record respectively, an approach I can suggest you is to use the InitializeRecord event of the XamDataGrid.
If you require any further assistance on this matter, please do not hesitate to ask.
Hi Tacho,
Thanks for the example you sent. The scenario I have it's quite different thought.
Let'say I have a xamDataGrid (Grid) with columns A, B, C, D, E configured on it. I allow, column choosing & filtering. When a user filters the Grid for any given column, I change the backcolor of that column to something else, to let the user know that the grid it's filtered. The first gesture would be to filter the Grid for column C, and remove the filter. To this point everithing looks fine. Then, I remove column B, filter/unfilter by column C, still works fine. The Problem is that when I make column B visible again, and I filter for column C, when I ask the VisualTreeHelper.GetChild(Parent, Index) for a LabelPresenter on this index position, it returns column D instead of C, even though the Index value it's correct. So I end up changing the BackColor to a different column.
So my question here is, what should I update/refresh in order to VisualTreeHelper.GetChild returns the right object?. Is there a better way to get a LabelPresenter?. Is there a better way to change the backcolor than this approach?.
Thanks in advance!