View previous topic :: View next topic |
Author |
Message |
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Thu Aug 02, 2018 6:19 pm Post subject: Change BackColor of specific rows in a list of row numbers |
|
|
I am attempting to color specific row numbers in a simple virtual tree, and it is escaping me how exactly to do that. It's not odd/even, it's for example:
Tree with 1000 rows, all cells have default Window backcolor.
For rows 5, 100, 245, and 763, change backcolor of these rows to PINK. That color should persist for ONLY these specific rows when they are visible in the tree as it is scrolled. All other rows remain Window color.
Thanks for any clues you might provide.
Mike _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Aug 03, 2018 2:02 am Post subject: |
|
|
You need to handle the GetCellData method and set the EvenStyle/OddStyle properties as shown below:
Code: | /// <summary>
/// Override the default GetCellData binding for special cases
/// </summary>
/// <param></param>
/// <param></param>
private void _virtualTree_GetCellData(object sender, Infralution.Controls.VirtualTree.GetCellDataEventArgs e)
{
// get the default binding for the given row and use it to populate the cell data
//
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (e.Row.ChildIndex == 5)
{
Style highlightStyle = new Style(e.CellData.OddStyle);
highlightStyle.BackColor = Color.Red;
e.CellData.EvenStyle = highlightStyle;
e.CellData.OddStyle = highlightStyle;
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Fri Aug 03, 2018 5:37 am Post subject: Change BackColor of specific row |
|
|
Thanks. I ALMOST had it right. I am using e.Row.RowIndex instead of ChildIndex because there are no nested rows in this data structure, just a simple table being shown.
Using VirtualRecordsets object bindings in the tree. I assemble a generic integer list of rows to color by searching the recordset based on other business rules:
int ix = myRs.FindUsingPrimaryKey(primarykey);
iList.Add(ix+1); // 0 based list in recordset to 1 based list in tree rows
Then, in my tree:
RowBinding b = myTree.GetRowBinding(e.Row);
b.GetCellData(e.Row, e.Column, e.CellData);
Style myStyle = new Style(e.CellData.OddStyle);
if (iList.Contains(e.Row.RowIndex))
{
// color me whatever, as you suggest
}
else
{
// return my color to Window
}
My problem was I was not creating the Style properly. Thanks for the sample code how to CORRECTLY create and modify a style.
cheers _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Fri Aug 03, 2018 5:03 pm Post subject: BackColor issue still |
|
|
Fooled myself into thinking this worked completely, still have an issue.
My tree has 17 rows showing on the screen. When the screen comes up, rows 21 and 121 should be in alternate color. However, if I scroll down so that row 21 is visible AT FIRST, the row has NOT been colored. I have to scroll down so that row 21 is off screen up top, then scroll back up, and all is then well from that point forward.
Not sure what that issue is. I do a Refresh() on the tree after changing the integer list that drives the alternate backcoloring. Apparently this does not trigger GetCellData as I expected.
Programmatically moving the scroll around surprisingly does NOT fix this. Only moving the scroll with the mouse fixes this.
Do you have any suggestions how to force the GetCellData to reprocess correctly after the integer list is changed?
Thanks. _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Aug 04, 2018 12:35 am Post subject: |
|
|
Instead of calling Refresh you need to call UpdateData. Refresh will repaint the screen but it does not trigger the data events to be refired. _________________ Infralution Support |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Sat Aug 04, 2018 3:27 am Post subject: BackColor |
|
|
Sorry, don't see what data structure to call UpdateData on. The tree won't allow me to call it directly. I think I have version 4.8.8.
Please treat me as completely ignorant here.
Thx for your patience. _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Aug 04, 2018 7:22 am Post subject: |
|
|
Sorry that should have been VirtualTree.UpdateRowData method that you need to call. _________________ Infralution Support |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Sat Aug 04, 2018 5:08 pm Post subject: Backcolor |
|
|
I really appreciate your help, don't misunderstand me. But according to your documentation, UpdateRowData, UpdateRows, et al, only work for rows BEING DISPLAYED.
I need to change the backcolor asignment for rows which MAY NOT currently be displayed, so that, when I scroll to them, their color is changed.
So far, NOTHING we've done here produces the result that when the screen comes up, and I scroll down to row 21, it is backcolored. It is not. I have to scroll it up past the top of the screen, then scroll up and THEN it is colored, and things work correctly from that point.
Sorry this is such a bother
Thx _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Sat Aug 04, 2018 5:16 pm Post subject: Backcolor |
|
|
Yes, I just verified that GetCellData is NOT called while the form containing the virtual tree has not yet been displayed and the UI message loop running. This is why programmatically scrolling past the line which should be colored does NOT update the backcolor, that code is never called until the tree is actually visible.
Would love to see a way around this, so that when the screen comes up, things are colored properly.
Thx _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Sat Aug 04, 2018 5:25 pm Post subject: Backcolor |
|
|
Answered my own question, my last comment gave me an idea. This is what I had to do to get it to work correctly:
private void myForm_VisibleChanged(object sender, EventArgs e)
{
if (myTree.Visible)
{
myTree.UpdateRows(true);
}
}
This takes care of that pesky case where the form is first being loaded upon program startup and the row list to be colored is first assigned. Once the form is assured visible, then the tree processes UpdateRows(bool) correctly, even for hidden rows that are not visible.
Then, for the case where the row list is reset:
public void setBackColors(List<int> iList)
{
colorMeDifferent = new List<int>(iList);
myTree.UpdateRows(true);
}
This appears to work under all conditions.
Thanks for all your help. It certainly helps to talk things out.
cheers _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
MikeR
Joined: 25 Jun 2016 Posts: 29
|
Posted: Sat Aug 04, 2018 5:28 pm Post subject: Backcolor |
|
|
..and the boolean is not strictly necessary in this case as the () overload processes identically.
thanks, and cheers _________________ Thanks,
-- Mike R. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Aug 05, 2018 7:03 am Post subject: |
|
|
Glad you got it working. Just to clarify your earlier comments:
Quote: | But according to your documentation, UpdateRowData, UpdateRows, et al, only work for rows BEING DISPLAYED.
I need to change the backcolor asignment for rows which MAY NOT currently be displayed, so that, when I scroll to them, their color is changed. |
Virtual Tree is data driven. That means that what is displayed is just a visual representation of your underlying data - and it only creates visual representations (Widgets) for the actual rows currently being displayed.
For performance it does however cache some information about the current rows being displayed (which was retrieved from your data by GetCellData/GetRowData). The UpdateRowData method allows you to tell Virtual Tree that the data assoicated with the rows has changed and it should update the cached data by calling GetCellData/GetRowData again. The UpdateRows method tells Virtual Tree that actual rows being displayed have changed (ie new rows added, rows deleted or reordered) _________________ Infralution Support |
|
Back to top |
|
|
|