C# – How to insert hyperlinks in ListView

asp.netclistview

I am trying to make Link Web / link info directory in C# where a user can save his links.

The following is my code:

private void Form1_Load(object sender, EventArgs e)
{
    Int i=0;
    listView1.View = View.Details;
    listView1.GridLines = true;
    listView1.Columns.Add("Links",250,HorizontalAlignment.Center );
    listView1.Columns.Add("Name", 250, HorizontalAlignment.Center);
}

private void button1_Click(object sender, EventArgs e)
{
    listView1.Items.Add(textbox1.text);
    listview1.Items[i].subitems.add("textbox2.text")
}

textbox2 contains the hyperlink but when I insert it displays as text, not as a hyperlink.

Best Answer

Use ObjectListView -- an open source wrapper around a standard ListView. It supports links directly:

Also have a look at the DataGridView control which has support for LinkLabel.

Using this control, you get all the functionality of the details view in a ListView, but with more customisation per row.

Also you can set one property to true --> listView1.HotTracking = true; You code will look like this:

private void button1_Click(object sender, EventArgs e)
    {
        listView1.Items.Add(textbox1.Text);
        listView1.HotTracking = true;

        listView1.Items[i].SubItems.Add("hyperlynk2.text");
    }