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 

How to avoid repeating values in a column?

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



Joined: 05 Apr 2012
Posts: 2
Location: Sydney, Australia

PostPosted: Thu Apr 05, 2012 3:34 am    Post subject: How to avoid repeating values in a column? Reply with quote

We display data in a table format. We want to customise this so that where several adjacent rows share the same value in a specific column, only the first row will display the value and the other rows are blank in that column. This display style resembles groups in a ListView.

Below is an example of what we wish to achieve.

An excerpt of the existing list looks like:

Code:
Entry1   Text   Date
Entry1   Text   Date
Entry1   Text   Date
Entry2   Text   Date
Entry2   Text   Date
Entry3   Text   Date
Entry4   Text   Date
Entry1   Text   Date

and we want to dynamically force it to look like:

Code:
Entry1   Text   Date
         Text   Date
         Text   Date
Entry2   Text   Date
         Text   Date
Entry3   Text   Date
Entry4   Text   Date
Entry1   Text   Date

When we remove the cell data, we are using the cell tooltip to display what was previously displayed.

We still require the underlying object for other purposes.

Our VirtualTree descendant class is bound to a data model via an IList collection.

We have tried a few approaches to prevent the repeating cell values, mostly using GetCellData. OnLayout seems likely to be useful.

The problem is that when scrolling, the logic for comparing 'current' versus 'previous' fails. This is most obvious when scrolling up, but also when scrolling many pages down. By 'current' I mean the CellData value in the handler for GetCellData; 'previous' is the value saved during the preceding call to the handler.

At the moment we are working on a solution that overrides OnLayout, as follows:

    Call base.OnLayout.
    For each row, set a cell to blank if the nearest non-blank cell above it has the same value.
The problem here is: how to set the displayed cell value, as opposed to using SetCellValue which changes the underlying bound object?

Alternatively, could you suggest a better approach to solving this?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sat Apr 07, 2012 12:28 am    Post subject: Reply with quote

I don't think that you want to use OnLayout to do this - otherwise I think you will find that the results will depend on what data has previously been displayed (ie were we scrolling, paging etc).

Instead I think you should use the GetCellData event and if the previous item in the parent collection had the same underlying data for that cell then set the CellData.Format property to an empty string. This means that the data won't be displayed but doesn't affect the actual item associated with the cell. I prototyped this by modifying one of the sample projects and it works. See the following code:

Code:
private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
    // Use the binding to get the default values
    //
    Row row = e.Row;
    RowBinding binding = _virtualTree.GetBindingForRow(row);
    binding.GetCellData(row, e.Column, e.CellData);

    // for the main cell check that the name isn't the same as the previous
    // row
    //
    if (e.Column == colMain)
    {
        int index = row.ChildIndex;
        if (index > 0)
        {
            IList items = row.ParentRow.ChildItems;
            Part prevPart = items[index-1] as Part;
            Part thisPart = row.Item as Part;
            if (prevPart.Name == thisPart.Name)
            {
                e.CellData.Format = "";
                e.CellData.ToolTip = thisPart.Name;
                e.CellData.AlwaysDisplayToolTip = true;
            }
        }
    }
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
groverboy



Joined: 05 Apr 2012
Posts: 2
Location: Sydney, Australia

PostPosted: Tue Apr 10, 2012 2:05 am    Post subject: Reply with quote

Many thanks for your suggestion: it works very well here.

Also, it's good to know that CellData.Format can be used like this to suppress the displayed value.

Thanks again. Very Happy
Back to top
View user's profile Send private message
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