Add a clickable link to a listview as an item...

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I have a listview and I want to add a link and when clicked goes to a webpage.. but im not sure what the code is..

I need it to be like ListView1.Items.Add(CODE HERE)
 
The main problem is that the Listview
1. Catches and handles the click event
2. Only displays text

To make this work you will have to catch the event from the ListView and then determine what to do with it. I am about 90% certian you can't just add a special object (or text) that when clicked in a listview will act as a link to the internet. Basically it is going to be more than just a one step process. You'll have to catch the click event, determine what you clicked and then serve it.

Another possibility is creating a custom listview control. Read this from the MSDN. I have not tried to do this myself but this looks like it would be something worth checking out.
 
well, since it will be too complicated to do, or impossible even, I have found a different way to do what I need to have done, thanks.
 
What's your solution? I am intersted to know how you worked around this. Did you redesign? Sacrafice Features? Figure out a work around?
 
mskeel said:
What's your solution? I am intersted to know how you worked around this. Did you redesign? Sacrafice Features? Figure out a work around?

Why not just check which item was clicked and hold the url in the Tag info of each item.
 
Right. I agree that the only way is to check wich item is clicked and then take appropriate action. Whether you do that through tags or some other method of holding a 1:1 relationship of items:urls it doesn't really matter (I guess it does but that isn't really important right now). But is there a way to make an object itself go to a webpage? Essentially like adding a link to the listview instead of an object. At least that is what I took from the initial meassage.

What would really be cool if there was an object that you could add to a listview that would take care of such an operation for free. Something like an internet link listview object, so that anytime you want to do something like this, all you have to do is instantiate one of these objects and add it to your listview and you get all of the action, tag, internet serve stuff for free.

At least that's the direction that I was headed.
 
mskeel said:
Right. I agree that the only way is to check wich item is clicked and then take appropriate action. Whether you do that through tags or some other method of holding a 1:1 relationship of items:urls it doesn't really matter (I guess it does but that isn't really important right now). But is there a way to make an object itself go to a webpage? Essentially like adding a link to the listview instead of an object. At least that is what I took from the initial meassage.

What would really be cool if there was an object that you could add to a listview that would take care of such an operation for free. Something like an internet link listview object, so that anytime you want to do something like this, all you have to do is instantiate one of these objects and add it to your listview and you get all of the action, tag, internet serve stuff for free.

At least that's the direction that I was headed.

You wouldn't really need to imbed a new object into the listview. You could use the listview as it is and like I said check for which item was clicked and then have a function to start your web browser and send the tag(url) as the arguments. Although if you wanted to create a new object(possibly inherit from LinkLabel?) so that you wouldn't need to copy/paste/reprogram the function then I guess you could do that... Just seems like alot of extra work for a simple action/reaction.

I am interested to know what Lanc did though, instead of using the listview.
 
Right, it would be a lot of extra work for someone to make, but once it's made you'd be able to just drop it in anywhere and it would just work. And that's the whole point, reusable, discrete, standalone code. Copying and pasting (or rewriting) a function from scratch can introduce many more problems and be just as much work in the long run.

Though, this really only matters if it is an object that is actually reused. If you coudl also attach it to files and launch Windows Explorer, that would be awesome too. And, if you could generalize it to attach a pointer and then launch a function that would be spectacular. But I don't know wether you can generalize it that far. I am kind of stretching thins a little bit and I really haven't investigated it that heavily, though I am interested to the point where I may in the near future.

So what'd you end up doing Lanc?
 
Back
Top