Menu

#145 HighlightTextRenderer doesn't work

C#_v2.8.1
wont-fix
1
2015-04-07
2015-04-02
knyazs
No

Hi Phillip,

I spend few hours trying to make TreeListView to show highlighted items but unsuccessfully.

Before I start putting code, let me just explain that I use TreeListView control and I really have tree structure.

First I tried the code available in 'Learn to Cook':

TextMatchFilter filter = new TextMatchFilter(this.treeListView1, toolStripTextBox1.Text);
this.treeListView1.DefaultRenderer = new HighlightTextRenderer(filter);

But that didn't work. I added:

this.treeListView1.Refresh();

But that didn't help either. Then, I added Renderer to one of the columns (not first column):

TextMatchFilter filter = new TextMatchFilter(this.treeListView1, toolStripTextBox1.Text);
this.treeListView1.DefaultRenderer = new HighlightTextRenderer(filter);
this.olvColumnObjectID.Renderer = new HighlightTextRenderer(filter);

And then it started to work but for all columns except first one. After that I modified third row by putting first row instead:

TextMatchFilter filter = new TextMatchFilter(this.treeListView1, toolStripTextBox1.Text);
this.treeListView1.DefaultRenderer = new HighlightTextRenderer(filter);
this.olvColumnObjectName.Renderer = new HighlightTextRenderer(filter);

But then strange thing happened - highlighter started working normally but tree lines, pluses and minuses 'disappeared'.

Please check attachment.

If I am doing something wrong, please let me know.

Thanks,
Miljan

1 Attachments

Discussion

  • Phillip Piper

    Phillip Piper - 2015-04-07

    Sorry, this isn't very clear.

    On a TreeListView, the DefaultRenderer is used for all columns except the first. The first column is drawn by the TreeColumnRenderer, which has to be an instance of TreeRenderer. TreeRenderer already supports text highlighting. You just need to change the Filter property.

    So your code just needs to add a single line to update the Filter property:

    TextMatchFilter filter = new TextMatchFilter(this.treeListView1, toolStripTextBox1.Text);
    this.treeListView1.DefaultRenderer = new HighlightTextRenderer(filter);
    this.treeListView1.TreeColumnRenderer.Filter = filter;
    
     
  • Phillip Piper

    Phillip Piper - 2015-04-07
    • status: open --> wont-fix
     

Log in to post a comment.