View previous topic :: View next topic |
Author |
Message |
billcch
Joined: 19 Jan 2007 Posts: 44
|
Posted: Mon Sep 24, 2007 4:37 pm Post subject: hight lighting the ancestor rows of the selected row |
|
|
We are setting EnsureVisible to false when a node is selected, but we would like to hightlighting (change background color as light green) all it's ancestors, so user will know where the selected node might located. Could you show us how can we do it? Thanks. |
|
Back to top |
|
|
billcch
Joined: 19 Jan 2007 Posts: 44
|
Posted: Mon Sep 24, 2007 4:59 pm Post subject: change selection color |
|
|
the default selection color is blue, and in some of computers, it become very dark blue, how can we change the selection color? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Sep 24, 2007 11:14 pm Post subject: |
|
|
Quote: | how can we change the selection color? |
Set the RowSelectedStyle.BackColor
Quote: | We are setting EnsureVisible to false |
I'm not sure what you mean by this? EnsureVisible is a method not a bool property.
Quote: | but we would like to hightlighting (change background color as light green) all it's ancestors, so user will know where the selected node might located. Could you show us how can we do it? |
Do you mean that whenever a row is selected you want to highlight its ancestors - or do you mean that you will provide a button or menu which will allow the user to highlight the ancestors of the currently selected row?
The first option is probably fairly difficult to do efficiently. The second option is probably better. To do this you would need to programmatically handle the GetRowData and GetCellData events and for rows that are ancestors of the currently selected row you would set the Odd and Even Styles to a style with a different BackColor. See the FAQ on setting styles for cells for more information.
You can use the Row.IsDescendant method to determine whether a row is ancestor of the selected row. To force Virtual Tree to update the data an styles you need to call VirtualTree.UpdateRowData when the button is clicked. You could also do this whenever selection changes (to implement option 1) however there is a performance overhead to calling UpdateRowData everytime selection is changed. _________________ Infralution Support |
|
Back to top |
|
|
billcch
Joined: 19 Jan 2007 Posts: 44
|
Posted: Mon Sep 24, 2007 11:54 pm Post subject: |
|
|
Thanks.
Quote: | We are setting EnsureVisible to false |
My mistake, I means we are not calling this method.
Quote: | Do you mean that whenever a row is selected you want to highlight its ancestors - or do you mean that you will provide a button or menu which will allow the user to highlight the ancestors of the currently selected row? |
We would like to have the first option - whenever a row is selected you want to highlight its ancestors. We are providing the same behavior as Maya outliner in our application.
The Odd and Event Styles have been used for another purpose, beside Odd and Event Style, do we have any other option to change row's back color? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Sep 25, 2007 12:15 am Post subject: |
|
|
Quote: | The Odd and Event Styles have been used for another purpose, beside Odd and Event Style, do we have any other option to change row's back color? |
This set me thinking - there is a better way to do what you want. You need to create a custom RowWidget and CellWidget class as follows:
Code: | class RowWidgetEx : RowWidget
{
public RowWidgetEx(PanelWidget panel, Row row)
: base(panel, row)
{
}
public override Style GetActiveStyle()
{
Row selectedRow = Tree.SelectedRow;
if (selectedRow != null && selectedRow.IsDescendant(Row))
return GetSelectedStyle();
else
return base.GetActiveStyle();
}
}
class CellWidgetEx : CellWidget
{
public CellWidgetEx(RowWidget rowWidget, Column column)
: base(rowWidget, column)
{
}
public override Style GetActiveStyle()
{
Row selectedRow = Tree.SelectedRow;
if (selectedRow != null && selectedRow.IsDescendant(Row))
return GetSelectedStyle();
else
return base.GetActiveStyle();
}
} |
Then you need to set Virtual Tree to use these custom widgets - either by deriving a new class from VirtualTree and overriding CreateRowWidget and CreateCellWidget or by setting the RowWidgetCreator/CellWidgetCreator delegates.
The above assumes you have set AllowMultiSelect to false (ie only a single selection). _________________ Infralution Support |
|
Back to top |
|
|
billcch
Joined: 19 Jan 2007 Posts: 44
|
Posted: Sun Jun 15, 2008 6:55 pm Post subject: |
|
|
Thanks. There is one issue, if SelectionMode is FullRow, your solution has no problem; but when SelectionMode is MainCellText, the cell back color won't change (only change row back color). |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Jun 15, 2008 11:11 pm Post subject: |
|
|
This is because the logic for MainCellText selection mode is a bit different. If you are using this mode you will need to override the CellWidget.PaintForeground method something like:
Code: | protected override void PaintForeground(Graphics graphics, Style style, bool printing)
{
Row selectedRow = Tree.SelectedRow;
if (selectedRow != null && selectedRow.IsDescendant(Row)&&!printing)
{
style = GetSelectedStyle();
string text = Text;
Rectangle textBounds = GetTextBounds();
Rectangle selectBounds = GetActualTextBounds(graphics, textBounds, style, text);
selectBounds.Inflate(style.BorderWidth, 0);
PaintSelectedTextBackground(graphics, selectBounds, style);
}
base.PaintForeground(graphics, style, printing);
}
|
With this code you don't need to create a custom row widget or override the GetActiveStyle. _________________ Infralution Support |
|
Back to top |
|
|
|