Firstly I am using AppStylist setting the Base->Row HotTracked Background Color to PaleGreen.
On my Windows Form the grid appears as designed in the AppStylist with the HotTrack on rows showing Pale Green. However when I change the color of some columns as below the CellAppearance stops the HotTrack working for the columns where the color has been changed. The other columns continue to display the HotTrack correctly.
gridMain.DisplayLayout.Bands[0].Columns["colX"].CellAppearance.BackColor = System.Drawing.Color.Yellow;
Adding the line of code below after changing the column's cell appearances makes no difference.
gridMain.DisplayLayout.Bands[0].Override.HotTrackRowAppearance.BackColor = Color.Red;
Why does this happen and what would be the correct method to change the back color of some columns and still allow the HotTrack to work for all columns?
Hi,
As a general rule of thumb, the grid tries to resolve the more specific appearance and give it precedence over a less specific appearance.
In some cases, this can be hard to define. Which is more specific, a column or a row? In this case, it looks like it was decided that the column is more specific than a row, so the column's CellAppearance gets resolved first.
In code, the grid has ways to handle this. In addition to the HotTrackRowAppearance, there is also a HotTrackRowCellAppearance, which affects the cells in the hot-tracking row. This appearance takes precedence over the CellAppearance of a column.
However, I don't see any way to do this in AppStyling. There isn't any way to translate this into UIRoles or states, since it's basically another appearance that applies to the same UIRole (UltraGridRow) and the same state (HotTracking).
So the only way I can see the achieve what you want is... do not set any appearance on the UltraGridRow's HotTracking state in your isl file. Instead, simply create a Resource in the isl file with the HotTracking colors you want. Then, in code, you can set the HotTrackRowCellAppearance.StyleResourceName property to the name of the resource. This allows you to define the HotTracking appearance on the row in your isl file, and still have it override the CellAppearance on the column.
The down side is that it requires a single line of code for each grid you are using.
Thank you for the explanation and suggestion Mike.
The solution you describe is more or less something I tried myself while attempting to overcome this problem and rejected as the HotTrackRowAppearance is not triggered for selected rows (the desired effect) while the HotTrackRowCellAppearance is triggered for selected rows.
The best solution I can think of is to use the MouseMove event to switch the HotTrackRowCellAppearance based on the Selected property of the row which the mouse is over (i.e. When over a selected row have the HotTrackRowCellAppearance equal the SelectedRowAppearance and when over anything else Color.PaleGreen). Obviously this will require coding on a per grid basis or the grid could be inherited by a custom control with this functionality added.
I would appreciate any suggestions to improve the solution I have described, the code is below.
private void gridMain_MouseMove(object sender, MouseEventArgs e){ this.activegrid = (sender as Controls.Grid);
Infragistics.Win.UIElement mouseupUIElement = this.activegrid.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y)); if (mouseupUIElement == null) return; UltraGridRow mouseupRow = (UltraGridRow)mouseupUIElement.GetContext(typeof(UltraGridRow)); if (mouseupRow == null) return; if (this.activegrid.Rows[mouseupRow.Index].Selected) this.activegrid.DisplayLayout.Override.HotTrackRowCellAppearance.BackColor = Color.Green; else this.activegrid.DisplayLayout.Override.HotTrackRowCellAppearance.BackColor = Color.PaleGreen;} Thanks,Paul
Infragistics.Win.UIElement mouseupUIElement = this.activegrid.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
if (mouseupUIElement == null) return;
UltraGridRow mouseupRow = (UltraGridRow)mouseupUIElement.GetContext(typeof(UltraGridRow));
if (mouseupRow == null) return;
if (this.activegrid.Rows[mouseupRow.Index].Selected) this.activegrid.DisplayLayout.Override.HotTrackRowCellAppearance.BackColor = Color.Green; else this.activegrid.DisplayLayout.Override.HotTrackRowCellAppearance.BackColor = Color.PaleGreen;}
Thanks,Paul