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 Paul,
pjholla said:the HotTrackRowCellAppearance is triggered for selected rows
Do you mean that the HotTrackRowCellAppearance is taking precedence over the SelectedRowAppearance? That seems correct to me, since HotTracking is pretty clearly the more specific appearance. But I can see it would also be reasonable to have it work the other way.
Personally, I like the new SelectionOverlay feature of the grid. This makes it so that the selected rows are highlighted with a semi-transparent overlay. That way, you can still see the selection regardless of any other appearance applied to the row. So you would be able to see that the row is both selected (or not) and hot-tracked at the same time.
Another potential option would be not to use SelectedCellAppearance and turn off the SelectedRowAppearance. I think the SelectedCellAppearance will affect the cells in a selected row, and SelectedCellAppearance might override the HotTrackingRowCellAppearance. I'm not sure if that is, in fact, the case, but it might be worth a shot.
A third potential solution would be to handle this yourself using a DrawFilter. The advantage of the DrawFilter is that you could create a single instance of the DrawFilter class and attach it to as many grids as you need. The down side is that it would require a significant amount of coding, and it would not be trivial code to write.
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
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.