View previous topic :: View next topic |
Author |
Message |
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Wed Sep 21, 2005 12:14 pm Post subject: DataRow Binding Style.BackColor |
|
|
Hello Support
I have set the Style.BackColor on a DataRow Binding. I expected that the entire row will be colored with the BackColor, but in fact only the Region that is not bound will be colored.
Is this a Bug? btw how to set a BackColor for a specific level?
Thanks and Best Regards
Giuseppe |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Sep 21, 2005 10:06 pm Post subject: |
|
|
No this isn't a bug. The problem is that you can either view a table as a collection of columns or as a collection of rows. So you can set up the style hierarchy to make it easy to change styles by column or by row - but not both (at least not without becoming very complicated). We made the decision that it was more common to want to change the style by column and set up the style hierarchy accordingly.
You can still change the style for a single row - but you need to change the style for each cell of the row (as well as the row). If you are using Object Bindings this is still easy - simply select all the CellBindings for the row in question and the row binding itself (by using the shift or control keys when selecting). Then change the style for all of them at once. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Thu Sep 22, 2005 7:48 am Post subject: |
|
|
Hello Support
I hope you don't get mad about all my posts.
Setting the CellBinding BackColor is ok. But with this implementation is not possible to set the BackColor for a VT.Column that is not Bound to a DataColumn.
The Only way to set the BackColor for the entire Row (based on the Level) is on "GetCellData". This is a little bit inconvenient
Best Regards
Giuseppe |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Sep 25, 2005 9:55 am Post subject: |
|
|
You can create a CellBinding for a column even if you are programmatically setting the CellData.Value in the GetCellData. In fact this is a good idea since you can let the CellBinding do most of the work and only do the bits programmatically that really can't be done at design time. The first line of code in your GetCellData event/method should call GetRowBinding to get the rowbinding and the call the RowBinding.GetCellData method. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
NJDRZ Guest
|
Posted: Wed Nov 09, 2005 9:49 pm Post subject: determing a row's backcolor based on a cell value |
|
|
How can I apply a unique backcolor to a row based on the value of a cell? For example if Column 1 has the value of "A" the backcolor is set to blue and for a value of "B" the backcolor is to green. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Nov 09, 2005 11:27 pm Post subject: |
|
|
If there are a fixed number of different styles that you want to apply then the best way to do this is to create a separate RowBinding for each type of row and set up the styles (colors etc) in the RowBindings editor. Then you can handle the GetBinding event (or override the GetRowBinding method) to select the row binding (and hence visual style) based on the item properties.
An alternative is to handle the GetRowData and GetCellData events (or override the corresponding methods) and set the OddStyle and EvenStyle properties of the CellData/RowData programmatically. Note that because rows share references to styles (to conserve resources) you can't just set the BackColor of the existing style - as this will change the colors of all rows using that style. Instead you need to assign a separate style. You can create new styles on the fly in the GetRowData/GetCellData methods eg
Code: |
private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
// get the default settings using the row binding
//
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
// check if you want to highlight this item
//
if (e.Row.Item == "A")
{
Style highlightStyle = new Style(_virtualTree.RowStyle);
highlightStyle.BackColor = Color.Red;
e.CellData.OddStyle = highlightStyle;
e.CellData.EvenStyle = highlightStyle;
}
}
|
This has the performance disadvantage that you are creating new styles all the time - so it would be better to setup the style at initialization in a member variable if possible and then just assign it in the GetCellData/GetRowData events. _________________ Infralution Support |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|