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!
Thank you for the feedback you have provided.
I have modified the sample application from my previous reply according to the behavior you have described. I have set the HeaderPrefixAreaDisplayMode property of the XamDataGrid's FieldLayoutSettings to FieldChooserButton. In order to achieve your functionality I have handled Loaded event of the LabelPresenter and the RecordFilterChanged of the XamDataGrid.
In the Loaded event of the LabelPresenter, I get the value of the default Background property of the initially loaded LabelPresenter and store it in a private field. We do this only once to make sure the value of the field never gets to change again since it is the default one. Afterwards I check the conditions count of the current field for the filtering and I set the Background property respectively - LightGreen if the field has been filtered and default value otherwise.
In the RecordFilterChanged event of the XamDataGrid I have used the FindVisualChildren method to get all the current LabelPresenters within the XamDataGrid. By iterating through the LabelPresenters I get the one corresponding to the field whose filter that has been changed. Afterwards I make the same conditions count check for the current field's filtering and set the Background property respectively.
Would you please take a look at the sample application and if your issue is still reproduced or this is not the behavior you were aiming for, would you please modify the sample so the issue is reproduced and send it back to me.
Thank you for your feedback. I am glad to know that I was able help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.
If you require any further assistance on this matter, please let me know.
This is exactly what I needed. I was facing a similar approach, but for me your solution it's a nicer way to do it.
Thank you very much for your assistance!