View previous topic :: View next topic |
Author |
Message |
incentives
Joined: 31 Dec 2008 Posts: 5 Location: Israel
|
Posted: Wed Mar 11, 2009 2:26 pm Post subject: loop and style rows |
|
|
Hi support,
I want to change the back color of rows at run time,
when selection_changed is fired i want to change the back color of (only) the rows in the same level as the row that was selected.
is it possiable (and how) ?
thank you |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Mar 11, 2009 9:39 pm Post subject: |
|
|
To change the style for a single row programmatically you need to set the style for the Row (in GetRowData) and for each cell in the Row (in GetCellData). See this FAQ for details on how to do this.
The code below shows how to change the back color of rows at the same level as the selected row.
Code: | private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
RowBinding binding = _virtualTree.GetBindingForRow(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (_virtualTree.SelectedRow != null &&
_virtualTree.SelectedRow.Level == e.Row.Level)
{
Style highlightStyle = new Style(e.CellData.OddStyle);
highlightStyle.BackColor = Color.Red;
e.CellData.EvenStyle = highlightStyle;
e.CellData.OddStyle = highlightStyle;
}
}
private void _virtualTree_GetRowData(object sender, GetRowDataEventArgs e)
{
RowBinding binding = _virtualTree.GetBindingForRow(e.Row);
binding.GetRowData(e.Row, e.RowData);
if (_virtualTree.SelectedRow != null &&
_virtualTree.SelectedRow.Level == e.Row.Level)
{
Style highlightStyle = new Style(e.RowData.OddStyle);
highlightStyle.BackColor = Color.Red;
e.RowData.EvenStyle = highlightStyle;
e.RowData.OddStyle = highlightStyle;
}
}
private void _virtualTree_SelectionChanged(object sender, EventArgs e)
{
_virtualTree.UpdateRows();
} |
Note that we need to call UpdateRows in the SelectionChanged event to force the tree to repaint the other rows. _________________ Infralution Support |
|
Back to top |
|
|
incentives
Joined: 31 Dec 2008 Posts: 5 Location: Israel
|
Posted: Thu Mar 12, 2009 12:55 pm Post subject: Thanks |
|
|
thanks it's working ,
Another question, how can i make it so the keyboard arrow keys will navigate inside the tree, so for exaple i'm pressing down key and it will go the the cell below ?
thanks again ! |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Mar 12, 2009 9:47 pm Post subject: |
|
|
If you don't have an active editor then the arrow keys should work to navigate around the tree (see the sample projects). If an editor is active then, by default, the arrow keys are left to the cell editor control to handle ie for a text box the the left right arrows move the caret.
For CellEditors you can set the UsesUpDownKeys and UsesLeftRightKeys properties (in the Virtual Tree designer) to set whether or not the cell editor should receive these keys or whether Virtual Tree can use them for navigation. _________________ Infralution Support |
|
Back to top |
|
|
|