Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

loop and style rows

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
incentives



Joined: 31 Dec 2008
Posts: 5
Location: Israel

PostPosted: Wed Mar 11, 2009 2:26 pm    Post subject: loop and style rows Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Mar 11, 2009 9:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
incentives



Joined: 31 Dec 2008
Posts: 5
Location: Israel

PostPosted: Thu Mar 12, 2009 12:55 pm    Post subject: Thanks Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Mar 12, 2009 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group