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 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.
Many thanks for your help on this Alex. Your examples are clear and very enlightening.
I would thoroughly recommend anybody who comes from a VB6/ASP.Net/Winforms background to download Alex's project and spend a few hours digesting the methods he has used. Not only has he shown a good codebehind method for dealing with this type of situation but he has also shown how to use XAML dynamically using delegates and direct binding to colors stored in a datasource.
By cross-referencing some of the terms and concepts he has used I know have a much better understanding of how the WPF objects are structured and how to control the various aspects of visual styling that I needed to.
One little example of this is how to hide grid lines (although you may need to set a few more properties for different states of the highlighted/selected row):
<igDP:XamDataGrid.Resources><Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BorderHoverBrush" Value="Transparent"/></Style></igDP:XamDataGrid.Resources>
Anyway Alex Thanks a lot, excellent work.
Regards
Thanks Alex, I'll have a look, I'm sure I have a lot to learn about wpf as I come from an asp/winforms background. Apart from this issue your grid is fast and smooth and would suit my purpose very well.
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!
could you give me an example of using the RecordsInViewChanged event in this context please? I can't seem to make this work.
Actually a further update. I have now also noticed that all cells in a column are re-rendered when you horizontally scroll them out of and back into view so that means you would possibly have to handle 3 events just to maintain the state of your grid! Also the conditional rendering of different cells in different text colors is inaccurate and therefore unuseable in any case. I achieved what I am trying to do in the last version of our product with a VB6 listview with no difficulty.
Having spent many hours and searching your forum it seems that many people have had this problem but there doesn't seem to be a solution. I can't really waste much more time on this but I'll give it one more go before giving up. If this problem can be solved I will definitely buy the tools.
Firstly here is a code snippet showing how the process is run. I realise that this is probably not the most efficient way to do it as all visible records are re-evaluated each time the event fires but I haven't figured out the proper way to use the RecordsInViewChanged event. This method however should be re-rendering the visible rows every time this event is fired.
private void xamDataGrid1_RecordsInViewChanged(object sender, Infragistics.Windows.DataPresenter.Events.RecordsInViewChangedEventArgs e){ if (e.Source != null) { Record[] drc = xamDataGrid1.GetRecordsInView(false); foreach (Record r in drc) { DataRecord dr = r as DataRecord; if (dr != null) { if (((string)dr.Cells[5].Value).Trim() == "MR") { Style sRed = new Style(); Setter seRed = new Setter(); seRed.Property = CellValuePresenter.ForegroundProperty; seRed.Value = Brushes.Red; sRed.Setters.Add(seRed); dr.Cells[5].Field.Settings.CellValuePresenterStyle = sRed; dr.Cells[4].Value = "RED"; } else { Style sGreen = new Style(); Setter seGreen = new Setter(); seGreen.Property = CellValuePresenter.ForegroundProperty; seGreen.Value = Brushes.Green; sGreen.Setters.Add(seGreen); dr.Cells[5].Field.Settings.CellValuePresenterStyle = sGreen; dr.Cells[4].Value = "GREEN"; } } } }}
Below is a screen shot of a portion of the grid when initally loaded but not scrolled. All text is rendered black but the MR & MRS column should be colored the same as the description in the previous column.
The state remains the same if the scroll bar is dragged (ie RecordsInViewChanged event doesn't fire)
If you scroll records by clicking on the scroll bar end buttons colors are changed but the do not properly match their descriptions (image below). This however is not random the same mistakes happen every time you run the project.
Finally if you scroll horizontally and back again the whole column is re-rendered to one color (image below).
Is this just a limitation of the grid, a bug or is there a better way to do it? The color values CANNOT BE SET IN XAML as they are provided by the datasource at runtime.
thanks