I have a windows form app .NET 4 written in C# that runs a number of HTTP requests collecting data about various websites and then once finished I order the results with some LINQ e.g
Code:
if (this.Accounts.Count > 0)
{
// re-order list decending by No
var lengths = from element in this.Accounts
orderby element.No descending
select element;
foreach (AccountName ht in lengths)
{
name = ht.AccountName;
nocount = ht.No; // no I am ordering by
if (!String.IsNullOrEmpty(name))
{
link = "http://somelink.com/" + name;
// add the item to my function that appends rows to a listview
this.AddAccountNameToList(name, nocount, link);
}
}
}
and then I call a function to add the items sorted by the No descending (most at the top of the list) to the list view. As the app is multi threaded I use a delegate to actually add each item to the listview e.g
Code:
// add list to listview (which I want the link column to be a real link)
private void AddAccountNameToList(string AccountName, int count, string Link)
{
ListViewItem listViewItem1 = new ListViewItem();
ListViewItem.ListViewSubItem listViewSubItem1 = new ListViewItem.ListViewSubItem();
ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
// format values for the row
listViewItem1.Text = AccountName;
listViewSubItem1.Text = count.ToString("N0");
listViewSubItem2.Text = Link.ToString();
// add the two other columns to the list view
listViewItem1.SubItems.Add(listViewSubItem1);
listViewItem1.SubItems.Add(listViewSubItem2);
// add the list view item to the list view - mulit threaded so I need to use a delegate
this.AddAccountName(listViewItem1);
}
// adds list item to listview
private void AddAccountName(ListViewItem ListItem)
{
if (this.listViewAccountNames.InvokeRequired)
{
AddAccountNameCallback d = new AddAccountNameCallback(AddAccountName);
this.Invoke(d, new object[] { ListItem });
}
else
{
this.listViewAccountNames.Items.Add(ListItem);
}
}
Problem is that I want the actual link (3rd column) to be a clickable link that takes the user off to the URL I set.
How do I do this? Do I need to use a different control instead of a ListView like a Panel or can I add Link Elements as items into the ListView (I tried but failed with that)
any help would be much appreciated.
Thanks