c# - C#中使用列表框的超链接控件

标签 c# sharepoint-2013 farm-solution

是否可以在c#中的列表框中添加一个超链接控件列表?如果可能的话,我该怎么做?另外,我有两个文本框:一个用于标题,另一个用于 URL。当我添加一个新项目时,文本框中的值必须作为超链接添加到列表框中,其中,title 是超链接标题,URL 是超链接 URL。谁能帮帮我?

最佳答案

此代码非常简单,但希望这能帮助您入门。 我在链接中添加了一个 ID,这样您就可以拥有 2 个具有不同链接的相同显示值。希望这会有所帮助。

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Hyperlink_control_using_List_box
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<hyperlinks> hll = new List<hyperlinks>();
        private void Form1_Load(object sender, EventArgs e)
        {
            hyperlinks link1 = new hyperlinks();
            link1.hyperlink_id = 1;
            link1.hyperlink_name = "Google";
            link1.hyperlink_link = "www.google.com";
            hll.Add(link1);

            hyperlinks link2 = new hyperlinks();
            link2.hyperlink_id = 2;
            link2.hyperlink_name = "Facebook";
            link2.hyperlink_link = "www.facebook.com";
            hll.Add(link2);

            hyperlinks link3 = new hyperlinks();
            link3.hyperlink_id = 3;
            link3.hyperlink_name = "Yahoo";
            link3.hyperlink_link = "www.yahoo.com";
            hll.Add(link3);

            listBox1.DataSource = hll;
            listBox1.DisplayMember = "hyperlink_name";
            listBox1.ValueMember = "hyperlink_id";
        }

        private void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            foreach (hyperlinks link in hll)
            {
                if (listBox1.SelectedValue.ToString() == link.hyperlink_id.ToString())
                {
                    label1.Text = link.hyperlink_link;
                }
            }
        }
    }

    public class hyperlinks
    {
        public int hyperlink_id { get; set; }
        public string hyperlink_name { get; set; }
        public string hyperlink_link { get; set; }
    }
}

关于c# - C#中使用列表框的超链接控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31869796/

相关文章:

sharepoint - 沙盒解决方案似乎严重受损

c# - ComboBox 项目到多个文本框

c# - 在C#中生成任务并知道任务何时完成

c# - 在 WPF 中打开窗口时的新任务栏图标

c# - 如何调用整页 View (忽略渲染体)?

javascript - 共享点 365 : Get all items in a list (but says columns don't exist!)

javascript - Sharepoint 2013 中的事件单击单选按钮 JQuery

c# - 为什么我得到 i :0#. w|domain\\username 和 RunWithElevatedPrivileges domain\apppool?