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 

When drawing the contents of a cell how do I paint selection

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



Joined: 21 Feb 2008
Posts: 9

PostPosted: Wed Nov 26, 2008 11:33 am    Post subject: When drawing the contents of a cell how do I paint selection Reply with quote

I need to draw the contents of a cell myself so following other articles on this forum I use a type editor with the code below.

When the tree.SelectionMode = FullRow the selection highlighting is still painted but when I set the tree.SelectionMode = MainCellText the selection highlighting is not painted.

My question is how do I get the selection highlighting painted when tree.SelectionMode = MainCellText?


GetCellData event:
private void tree_GetCellData(object sender, Infralution.Controls.VirtualTree.GetCellDataEventArgs e)
{
MyData Node = (MyData)e.Row.Item;

if (e.Column == MyTreeColumn)
{
e.CellData.ShowPreview = true;
e.CellData.DrawPreviewBorder = false;
e.CellData.ShowText = false;
e.CellData.TypeEditor = MyTypeEditorInstance;
e.CellData.Value = Node;
}
}

My type editor:
internal class MyTypeEditor : Infralution.Controls.StandardValueEditor
{
public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context)
{
return true;
}

public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e)
{
// I do the painting here
}
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Nov 27, 2008 11:56 am    Post subject: Reply with quote

You can determine if the row is highlighted in the PaintValue event by getting the CellWidget from the context eg

Code:
public override void PaintValue(PaintValueEventArgs e)
{
    CellWidget cellWidget = e.Context as CellWidget;
    if (cellWidget != null && cellWidget.Row.Selected)
    {
          e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
    }
    else
    {
          e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
    }
}


This changes the colour of the cell background if the cell widget was selected. Using the TypeEditor mechanism like this however may not be the best option as it couples the TypeEditor for your type to the Virtual Tree. Instead you could consider writing a custom CellWidget and overriding the paint methods. See the section in help on writing custom widgets for Virtual Tree.
_________________
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