View previous topic :: View next topic |
Author |
Message |
andrewc
Joined: 21 Feb 2008 Posts: 9
|
Posted: Wed Nov 26, 2008 11:33 am Post subject: When drawing the contents of a cell how do I paint selection |
|
|
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 |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Nov 27, 2008 11:56 am Post subject: |
|
|
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 |
|
|
|