Click here to Skip to main content
15,910,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, I'm trying to add columns which contains hyperlinks similar to ASP.NET listview which will perform actions when clicked. I would preferably like to achieve this without having to use a customised tool.

The look I'm trying to achive is something similar to this.

Hopefully someone has a solution as I've been stuck on this for 2 hours now.

Thanks in advance

Danny
Posted
Updated 17-Jul-11 3:42am
v2

 
Share this answer
 
Comments
Danny Hulmston 16-Jul-11 7:02am    
I'm building the listview in C# Windows Forms not ASP.NET. I've already looked at this code and Windows Form listviews do not contain different templates to add hyperlinks to.
thatraja 16-Jul-11 9:56am    
I found a open source, see my answer.
You don't have to go to custom controls. Listview by itself capable of doing that. Here is MSDN example ListView Web Server Control Overview.[^]
 
Share this answer
 
Comments
Danny Hulmston 17-Jul-11 6:26am    
Thanks for your response but the question was for C# Windows Form Listview not ASP.NET Listviews.
Wonde Tadesse 17-Jul-11 8:13am    
So why you tagged as if it is ASP.Net
I found more than couple of things for you.

First of all I recommend this open source
ObjectListView[^] - Looks cool, excellent, nice, etc.,

CP articles
Embedding Controls in a ListView[^]
C# List View v1.3[^]
In-place editing of ListView subitems[^]
Extended ListView[^]
ContainerListView and TreeListView: Writing VS.NET design-surface compatible controls[^]
 
Share this answer
 
Comments
Danny Hulmston 17-Jul-11 8:17am    
These are brilliant open source tools!
Espen Harlinn 17-Jul-11 11:12am    
Nice set of links, my 5
I've developed a quick solution using a custom method which prevents the need for using an open source solution. First create the listview as you usually would and add a item to the listview using ListViewItem including the custom method below the ListViewItem.
C#
listView1.Columns.Add("Column 1", 50, HorizontalAlignment.Left);
listView1.Columns.Add("Column 2", 45, HorizontalAlignment.Left);
listView1.Columns.Add("Column 3", 45, HorizontalAlignment.Left);
listView1.MultiSelect = true;
listView1.FullRowSelect = false;
listView1.View = View.Details;
listView1.Activation = ItemActivation.OneClick;
listView1.LabelEdit = true;

ListViewItem lvi = new ListViewItem("Action");
lvi.SubItems.Add("Delete");
lvi.SubItems.Add("Copy");
lvi.UseItemStyleForSubItems = false;

// Custom Method
ChangeToUnderline(ref listView1, 0, Color.Blue);


Now the custom piece of code which will display the text as any colour you want with an underline.

C#
private void ChangeToUnderline(ref ListView lv, int ColumnIndex, Color color)
{
    foreach (ListViewItem lvi in lv.Items)
    {
        lvi.SubItems[ColumnIndex].Font = new Font("Microsoft Sans Serif", 8, FontStyle.Underline);
        lvi.SubItems[ColumnIndex].ForeColor = color;
    }
}


If you want to create a cell which looks like a hyperlink quickly I'm recommend using this method, otherwise if you have time I'd recommend one of the open source solutions mentioned earlier in this post by thatraja.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900