Hi
I am having difficulty disabling in cell editing in the whole grid. What I am looking for is behavior similar to an old fashioned list view in the report view (ie click a row anywhere to select the whole row).
I have tried playing with the SelectionTypeRecord, SelectionTypeField and SelectionTypeCell properties but they have no effect. I know this can be achieved on a cell by cell basis but this seems a bit of an inefficient way of doing it. Does anyone know why the aforementioned properties have no effect or am I just missing something?
Also could someone point me at how the change the colour of cell text in C# from the codebehind, I am new to WPF but am I looking at altering a style?
Thanks
Alan
Hello Alan,
Actually what you are looking for is CellClickAction property of the FieldSettings object in the XamDataGrid. You can set that to SelectRecord and when you click anywhere in the DataRecord, it will be selected.
You can change the color of the cell text in procedural code, throught the correspondant CellValuePresenter. You can use the static get methods of the CellValuePresenter (CellValuePresenter.FromCell(), CellValuePresenter.FromRecordAndField()) and then set its Foreground property.
If you would like to change that based on a cell value, you can use converters.
Please follow this link for more information on this (with the difference that the Background instead of Foreground is changed)
http://community.infragistics.com/forums/p/20644/74574.aspx#74574
Please let me know if you have any more questions on this.
Coming back on the text color I'm still having problems.
I need to set the text color of each row depending on a color supplied at run time by a field in the datasource. The color is set by the end user and can be anything. I have managed to get half way there using this code
private Style s;private Style s2;private Setter se;private Setter se2;private void xamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e){ //e.Record.DataPresenter.Background = Brushes.Red; DataRecord dr = e.Record as DataRecord;
if (dr != null) { if (((string)dr.Cells[5].Value).Trim() == "MR") { s = new Style(); se = new Setter(); se.Property = CellValuePresenter.ForegroundProperty; se.Value = Brushes.Red; s.Setters.Add(se); dr.Cells[5].Field.Settings.CellValuePresenterStyle = s; } else { s2 = new Style(); se2 = new Setter(); se2.Property = CellValuePresenter.ForegroundProperty; se2.Value = Brushes.Aquamarine; s2.Setters.Add(se2); dr.Cells[5].Field.Settings.CellValuePresenterStyle = s2; } } }
This kinda works when you scroll down the list but when you scroll back the event is no longer fired (I guess because of virtual loading) but all the items are re-rendered in aquamarine.
Any ideas please?
Alan,
Looking at the situation now, it looks much more simpler. Iteraring through the records and creating and assigning styles for all them and their cells is quite cumbersome and leads to some problems that you have experienced. The events like InitializeRecord, RecordInViewChanged, etc. are used rather to make changes in the Data than change their visual appearance, because thei presenters are not yet created. Virtualization techniques of the XamDataGrid makes this task even more difficult, however not impossible.
Please find the attached project that I created with the best 3 ways that I came up with for achieving this task. The WPF Framework and its binding engine are pretty "smart" in your scenario and binding to the Color cell's string value would be just enough for the foreground to change. Also,using converters will have the same desired effect. The third way changes this dynamically, as your approach, but slightly different.
Please let me know if you have further questions on this.
Cheers!
Hello Alex,
I've made a litte modification in your sample. I've set the theme="Onyx" in the XamDataGrid and it does not show the orange color when the mouse hovers the records. The background appear in grey color (my window configuration?). How can I preserve the Onyx theme and change the foreground of the cell at the same time?
Thank you very much.
I'm sorry. I've forgotten saying this effect occurs in Option 3 CellValuePresenter.
Just to make sure I am on the right track, when you hover over the cell, you want the color of the text (Red,Green) not to change, right?
No. The color of the text is a second effect.
What I mean is that Onyxs theme, when you move the mouse over the records, shows the row in orange .
DataRecordCellArea.BackGroundHover is grey and it should be the Onyx color.
Thanks for clearing that out. You have to "inherit" the style for the DataRecordCellArea from the one of the theme like this:
namespace for themes: xmlns:Themes="http://infragistics.com/Themes"
...
<Style TargetType="{x:Type igDP:DataRecordCellArea}" BasedOn="{x:Static Themes:DataPresenterOnyx.DataRecordCellArea}">