C# ObjectListView TreeListView - 除了使用 ModelFilter 之外,如何仅在 TreeViewList 中突出显示项目

C# ObjectListView TreeListView - How to highlight items only in TreeViewList other than using ModelFilter

我正在使用 ObjectListView.Official.2.9.1.nupkg
http://objectlistview.sourceforge.net/cs/index.html

Here is my sample code:

Currently I'm using ModelFilter and the problem was when i perform Collapse, the nodes went missing.
Explanation: http://objectlistview.sourceforge.net/cs/filtering.html#filtering-and-treelistviews

private void txtSearchInTable_TextChanged(object sender, EventArgs e)
{
    try
    {
        if (txtSearchInTable.Text == "")
        {
            this.treeListView1.ResetColumnFiltering();
            treeListView1.ExpandAll();
        }
        else
        {
            this.treeListView1.ModelFilter = TextMatchFilter.Contains(this.treeListView1, txtSearchInTable.Text);
            this.treeListView1.Refresh();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex + "", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}


是否有任何搜索和仅突出显示文本同时保持所有内容可见的功能?

更新:

TextMatchFilter filter1 = TextMatchFilter.Contains(treeListView1, txtSearchInTable.Text);
filter1.Columns = new[] { this.olvColumn1, this.olvColumn2, this.olvColumn3, this.olvColumn4 };
treeListView1.DefaultRenderer = new HighlightTextRenderer(filter1);

使用 DefaultRenderer 是可行的,但为什么只有第一列“olvColumn1”无法突出显示?即使我设置 olvColumn1.Searchable = true;

您可以使用 HighlightTextRenderer 突出显示和选择性过滤项目。

正如 Dialecticus 在一条评论中指出的那样,TreeListView 的第一列(与 ObjectListView) 需要特殊处理。

引自here

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;