Hi,
I just want to know how to change the background colour for a particular cell in XamlGrid. I want to do this in Code behind (C#). Could anyone please assist on this.
Many thanks in advance
Florence
I just want to know how to change the background colour for a particular cell on loading the XamGrid itself.
I want to do this in Code behind (C#). Could anyone please assist on this.
Thanks in advance
- Arthi
Hi Arthi,
You can change the background color in two ways.
One by creating a style for the CellValuePresenter of that particular cell or setting the editor's background of the CellValuePresenter to the new color. You can see all the default styles in the local directory on your computer : "~ \Infragistics\NetAdvantage for WPF 2008 Vol. 2\DefaultStyles".
Here is some source code with the Editor's Background.
DataRecord dr = xamDG.ActiveRecord as DataRecord;
CellValuePresenter cvpText = CellValuePresenter.FromRecordAndField(dr, dr.FieldLayout.Fields[0]);
XamTextEditor te = cvpText.Editor as XamTextEditor;
te.Background = Brushes.Red;
Hope this helps.
Hi Alex,
Thanks. It works but, if i scroll the grid then the cells background color is also scrolled.
Consider a Scenario, A column in the grid is mandatory and should show the bg color as red on exists of the row. This can be acheived. But if there are too many rows and the user tries to scroll down, then the bg color is appearing on the visible rows where actually it shoul not be.
How this can be solved? Can we use StyleSelector for this?
How can we force explicitly to set the style selector?
Is it possible to attach a screen shot or a sample project to take a closer look and gain a better idea of the problem? I think we will solve the problem much faster this way.
Alex.
This is my grid, here, i want to shoe red border for null value field. When i try to scroll down / up the borders are misplaced. for ex. 1001 - Age cell was bordered red, but when in scroll dow and up the redborder is coming in 1002 - age cell.Can you please help me in this regard?
I also fall across a similar problem with you, it puzzled me for several days.
But now I figured it out !!
It is quite easily to do this.
You can just set RecordContainerGenerationMode to PreLoad in XamDataGrid !!
here is for you reference:http://forums.infragistics.com/forums/p/29380/128390.aspx
Hello Arthi,
I will attach a project that does almost the same thing. I color the borders of cells like you, but in 3 different colors depending on the value of the cell.
Hope it would be helpful to you.