本文介绍了我可以显示在ListView的详细联系方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示了的ListView A组搜索结果。第一列包含搜索词,第二个显示匹配的数量。

I'm displaying a set of search results in a ListView. The first column holds the search term, and the second shows the number of matches.

有行数以万计,因此的ListView 是虚拟模式。

There are tens of thousands of rows, so the ListView is in virtual mode.

我想改变这一点,以便在第二列显示的匹配,而超链接,以同样的方式为的LinkLabel 显示链接;当用户点击该链接时,我希望收到,这将让我在其他地方我们的应用开拓了比赛的事件。

I'd like to change this so that the second column shows the matches as hyperlinks, in the same way as a LinkLabel shows links; when the user clicks on the link, I'd like to receive an event that will let me open up the match elsewhere in our application.

这是可能的,如果是这样,怎么样?

Is this possible, and if so, how?

编辑:我不认为我已经足够明确的 - 我想的的超链接在单个列,只是因为它是可能有的超链接一个的LinkLabel

I don't think I've been sufficiently clear - I want multiple hyperlinks in a single column, just as it is possible to have multiple hyperlinks in a single LinkLabel.

推荐答案

您可以轻松地捏造事实。请确保您添加列表视图中的项目有UseItemStyleForSubItems = false,所以你可以设置分项的前景色为蓝色。实施MouseMove事件,所以你可以强调链接,改变光标。例如:

You can easily fake it. Ensure that the list view items you add have UseItemStyleForSubItems = false so that you can set the sub-item's ForeColor to blue. Implement the MouseMove event so you can underline the "link" and change the cursor. For example:

ListViewItem.ListViewSubItem mSelected;

private void listView1_MouseMove(object sender, MouseEventArgs e) {
  var info = listView1.HitTest(e.Location);
  if (info.SubItem == mSelected) return;
  if (mSelected != null) mSelected.Font = listView1.Font;
  mSelected = null;
  listView1.Cursor = Cursors.Default;
  if (info.SubItem != null && info.Item.SubItems[1] == info.SubItem) {
    info.SubItem.Font = new Font(info.SubItem.Font, FontStyle.Underline);
    listView1.Cursor = Cursors.Hand;
    mSelected = info.SubItem;
  }
}

请注意,该代码段检查,如果第2列徘徊,根据需要调整。

Note that this snippet checks if the 2nd column is hovered, tweak as needed.

这篇关于我可以显示在ListView的详细联系方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:19