在C#Windows应用程序中的ListViewItem中搜索和突出显示功能 [英] search and highlight functionality in ListViewItem in c# windows application

查看:230
本文介绍了在C#Windows应用程序中的ListViewItem中搜索和突出显示功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用表单对listviewitem Windows应用程序进行搜索并突出显示功能.

I want to program search and highlight functionality in listviewitem windows application using forms.

推荐答案

让我通过说我当然不拒绝这种尝试来回答这个问题自以为是WinForms本机ListView的专家,我使用了3rd.我自己的代码中的Party ListView.

从我的快速研究中,您的代码似乎没有引起错误:但是,正如您所期望的那样,"TopItem属性不会将ListViewItem在ListView中的位置移动到ListView客户端显示矩形的顶部.

在我看来,"TopItem"与"EnsureVisible"具有几乎相同的效果:它只是使它显示在ListView的可见区域中.不幸的是,在我看来WinForms ListView控件没有``ScrollIntoView方法",也没有其他有用的方法来将给定的ListViewItem准确地定位在所需的ListView可见区域中.

您只需设置BackColor和/或选择通过搜索'FindItemWithText即可找到的匹配ListViewItem即可轻松模拟``突出显示''.

现在如果您的意图是实际上将找到的ListViewIte m移动到ListView的顶部:可以这样进行:
Let me disclaimer this attempt at an answer by saying that I certainly do not regard myself as an expert on the WinForms native ListView, and I use a 3rd. Party ListView in my own code.

From my quick study, it appears that your code is not causing an error: however, the ''TopItem property does not, as you may be expecting, move the position of a ListViewItem within the ListView to the top of the ListView client display rectangle.

''TopItem'' appears to me to have much the same effect as ''EnsureVisible'' : it just makes it show up in the visible area of the ListView. Unfortunately, it appears to me that the WinForms ListView Control has no ''ScrollIntoView method, or other useful way to position a given ListViewItem exactly where you want it in the visible area of the ListView.

''Highlighting'' is something you can easily simulate by just setting the BackColor, and/or selecting the matching ListViewItem found by searching with ''FindItemWithText.''

Now if your intent is to actually MOVE the found ListViewItem to the top of the ListView: that can be done like this:
private void button1_Click(object sender, EventArgs e)
{
  ListViewItem lv = listView1.FindItemWithText("AnyOldItem");

  if(lv == null) return; // or throw some error ....

  // move the found Item to the top of the ListView
  listView1.Items.Remove(lv);
  listView1.Items.Insert(0, lv);

  // simulate some highlighting ...
  lv.BackColor = Color.Yellow;
  lv.Selected = true;
}

我认为是...呃...不是很漂亮代码:).

希望其他人能为您提供更好的解决方案!

Which I think is ... uhhh ... not very beautiful code :).

I hope someone else gives you a better solution !


这篇关于在C#Windows应用程序中的ListViewItem中搜索和突出显示功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆