Hi,
I have found this thread: http://ko.infragistics.com/community/forums/t/71593.aspx
and had some success in adapting the answer to my needs.
What I'm still missing is a replace function and to highlight only the cells with the hits, not the whole rows.
How can I achieve that?
Best
Oliver
Hello,
I am just checking if there is anything else I can do for you.
Hello Oliver,
Thank you for your post.
I have been looking into it and the reason for the CellValuePresenters to be null is that the XamDataGrid is virtualizing its visual elements and creates visual elements only for the records and cells that are in view. When you try to get a CellValuePresenter for a cell that is not in view, CellValuePresenter.FromCell will return null.
I modified the previous sample application and change the approach to achieve the required functionality. In the sample I created style for CellValuePresenter to set the background color of matched cells. In it, I used MultiBinding to bind the Background of the CellValuePresenter to the Record, the Field and also the Tag of the XamDataGrid. In the converter of the MultiBinding, I am using the Record and the Field of the CellValuePresnter to get the Cell and based on its Tag property to set return the appropriate brush for the background. The third binding in the MultiBinding (the binding to the XamDataGrid's Tag) is used to trigger the whole MultiBinding when typing in the search TextBox. I modified the code behind of UserControl and added a list<Cell> 'cellResults' to store the cells. In the event handler of TextChanged event I loop all cells and for these cells that match with the criteria for searching I set the tag property and it to 'cellResults' collection.
The sample application is showing a custom approach that can be used as a guideline for implementing the functionality that you are looking for. Since implementing such custom features is outside of the scope of the developer support (you can read more details here: http://ko.infragistics.com/support/support-policies), if you need any help implementing such custom functionalities, I can suggest contacting our consulting team.
Thanks for choosing Infragistigs.
Hello Zhivko,
thanks for your help.
I'm searching in the whole grid, so I tried to reset the cell colors like that:
private void ResetAllCellColors() { foreach (DataRecord record in _grid.Records) { foreach (Cell cell in record.Cells) { var cellPresenter = CellValuePresenter.FromCell(cell); if (cellPresenter != null) cellPresenter.Background = Brushes.Transparent; } } }
Unfortunaltely cellPresenter is very often null (especially with high column numbers). What am I missing?
Edit
It seems to have something to do with the rendering of the grid. If I scroll fully to the right before my search, everything works as expected.
How can I fix this?
Hello Swanapil,
I have been looking into it. Currently the replace functionality that you want to achieve is determined to be a Product idea.
About highlighting: I modified the sample from the forum thread that you have provided to show you how you can achieve this functionality. Basically in the event handler of TextChanged event I used CellValuePresenter to change the background of the these cells that match with the criteria for searching. Also at the beginning of this event I set the background to transparent as default color, to reset it when changing the search criteria. I handled the LostFocus event of the textbox and in the event handler I set the background of cells back to the transparent.
Please let me know if you need any further assistance on this matter.
does the new product idea refer to the highlighting or the replace function?
Regards