如何创建一个的ListView点击链接? [英] How to create a clickable links in ListView?

查看:135
本文介绍了如何创建一个的ListView点击链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使ListView项内部URL点击。

我如何做到这一点?

我想它的工作方式是将用户存储链接以纯文本,然后当我检索链接我想使他们在点击的ListView

这是我如何检索从我的数据库条目,而read.GetString(2)拉URL值:

 如果(security.DecryptAES
    (read.GetString(1),storedAuth.Password,
    storedAuth.UserName)==网站密码)
{
    //计数网页的密码。
    countWeb ++;
    网络=新的ListViewItem();
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(2),storedAuth.Password,storedAuth.UserName));
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(5),storedAuth.Password,storedAuth.UserName));
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(6),storedAuth.Password,storedAuth.UserName));
    Web.Tag = read.GetInt32(0);
    lvWeb.Items.Add(网络);
}


解决方案

您想要做的第一件事就是给视觉反馈让用户知道产品点击。我只是随意假定URL是在第2列。添加MouseMove事件为ListView:

 私人无效listView1_MouseMove(对象发件人,MouseEventArgs E){
        VAR命中= listView1.HitTest(e.Location);
        如果(hit.SubItem =空&放大器;!&放大器; hit.SubItem == hit.Item.SubItems [1])listView1.Cursor = Cursors.Hand;
        否则listView1.Cursor = Cursors.Default;
    }

接下来的步骤是非常相似的,实行MouseUp事件来检测的分项目点击:

 私人无效listView1_MouseUp(对象发件人,MouseEventArgs E){
        VAR命中= listView1.HitTest(e.Location);
        如果(hit.SubItem =空&放大器;!&放大器; hit.SubItem == hit.Item.SubItems [1]){
            VAR URL =新的URI(hit.SubItem.Text);
            //等。
        }
    }

I am trying to make URL clickable inside of ListView item.

How do I do this?

The way I want it to work is to user store link in plain text, and then when I am retrieving the links I want to make them clickable in ListView.

This is how I retrieve entries from my database while read.GetString(2) pulls the URL value:

if (security.DecryptAES
    (read.GetString(1), storedAuth.Password, 
    storedAuth.UserName) == "Web Site Password")
{
    // Count Web passwords.
    countWeb++;
    Web = new ListViewItem("");
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(2), storedAuth.Password, storedAuth.UserName));
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(5), storedAuth.Password, storedAuth.UserName));
    Web.SubItems.Add(security.DecryptAES
        (read.GetString(6), storedAuth.Password, storedAuth.UserName));
    Web.Tag = read.GetInt32(0);
    lvWeb.Items.Add(Web);
}

解决方案

The first thing you want to do is give visual feedback to let the user know that the item is clickable. I'll just arbitrarily assume the url is in the 2nd column. Add the MouseMove event for the ListView:

    private void listView1_MouseMove(object sender, MouseEventArgs e) {
        var hit = listView1.HitTest(e.Location);
        if (hit.SubItem != null && hit.SubItem == hit.Item.SubItems[1]) listView1.Cursor = Cursors.Hand;
        else listView1.Cursor = Cursors.Default;
    }

The next step is very similar, implement the MouseUp event to detect a click on the sub-item:

    private void listView1_MouseUp(object sender, MouseEventArgs e) {
        var hit = listView1.HitTest(e.Location);
        if (hit.SubItem != null && hit.SubItem == hit.Item.SubItems[1]) {
            var url = new Uri(hit.SubItem.Text);
            // etc..
        }
    }

这篇关于如何创建一个的ListView点击链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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