View previous topic :: View next topic |
Author |
Message |
eheinz
Joined: 05 Jun 2007 Posts: 4
|
Posted: Tue Jun 05, 2007 4:14 pm Post subject: Access CellData without using GetCellData event |
|
|
I need to be able to change a cell's background color based on an event that occurs outside of the tree. So, the GetCellData never fires since the tree isn't involved in this external event.
When the external event occurs, I have access to the Row and I know which column the cell lies in, how can I retrieve the CellData from this information so that I can set the OddStyle/EvenStyle on the CellData object? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jun 05, 2007 11:08 pm Post subject: |
|
|
Virtual Tree is data driven. This means the state of the tree is based on the underlying state of the data. The mapping between the data state and the display state is done by the GetCellData event. This avoids any possibility of the display state getting out of synch with the data state. If the underlying data changes in some way then you need to tell Virtual Tree to update its display state. If your data source supports the IListChanged interface then generally this happens automatically when the data is changed.
In your case you should call the UpdateRowData(row) to force Virtual Tree to fire the GetCellData event for that row. _________________ Infralution Support |
|
Back to top |
|
|
eheinz
Joined: 05 Jun 2007 Posts: 4
|
Posted: Wed Jun 06, 2007 3:46 pm Post subject: |
|
|
Works thanks. |
|
Back to top |
|
|
eheinz
Joined: 05 Jun 2007 Posts: 4
|
Posted: Wed Jun 06, 2007 4:24 pm Post subject: Even/Odd style background color size |
|
|
It seems when I set the background color for CellData using Even/Odd Style it sets the correct color, but the size of the color block equals the largest cell instead of performing similiar to the color block if I just select a cell.
When selecting a cell, the color block around the text (dark grey) is trimmed to match cell text. This same behavior is desired when I change the Even/Odd Style's background color on a cell.
Is that possible? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Jun 06, 2007 10:32 pm Post subject: |
|
|
I assume you must be using SelectionMode of "MainCellText". In this mode only the cell text is highlighted when selecting. The Style backcolor however affects the whole of the cell. It would be possible to get the behaviour you want by creating a custom CellWidget and overriding the PaintBackground method - something like:
Code: | protected virtual void PaintBackground(Graphics graphics, Style rowStyle,
Style cellStyle, bool printing)
{
Rectangle bounds = GetActualTextBounds(graphics, GetTextBounds(), style, Text);
if (rowStyle.BackColor != cellStyle.BackColor)
{
cellStyle.DrawBackground(graphics, bounds);
}
} |
Note this assumes you are not using cell borders. If you want cell borders then you also need to draw them here. See the section in the online help about creating and using custom widgets. _________________ Infralution Support |
|
Back to top |
|
|
eheinz
Joined: 05 Jun 2007 Posts: 4
|
Posted: Thu Jun 07, 2007 1:46 pm Post subject: |
|
|
Is GetActualTextBounds part of your library or something I should create. I don't see this method in my version (2.5.4.0) |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 07, 2007 10:23 pm Post subject: |
|
|
Sorry I assumed you were using version 3 of Virtual Tree (for VS2005). Version 2.5 does not have this method. You would need to implement it yourself - something like:
Code: | protected Rectangle GetActualTextBounds(Graphics graphics, Style style)
{
Rectangle bounds = GetTextBounds();
string text = Text;
SizeF size = style.MeasureString(graphics, Text, bounds.Width);
bounds.width = size.Width;
return bounds;
} |
Note that the latest version for VS2003 is 2.7.0. Have you purchased Virtual Tree? If so you are able to upgrade to this for free. You can download it from our downloads page www.infralution.com/downloads.html. _________________ Infralution Support |
|
Back to top |
|
|
|