Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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

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?

EDIT: 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
370 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
  }
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...