Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a hyperlink in a listview

Status
Not open for further replies.

soulpumpkin

Programmer
Feb 18, 2005
79
US
Is this possible? I've tried using the following:
Code:
Dim link As New System.Web.UI.WebControls.HyperLink

        lstDuplicates.Columns.Add("Description", 250, HorizontalAlignment.Left)
        lstDuplicates.Columns.Add("Code - Worksheet Number", 250, HorizontalAlignment.Left)
        lstDuplicates.Columns.Add("File Name", 500, HorizontalAlignment.Left)

        'populate listview
        Do While x < (dataArray.Length - 1)
            If dataArray(x) = "" Then
            Else
                lvi = New ListViewItem
                lvi.Text = Trim(dataArray(x))
                lvi.SubItems.Add(Trim(dataArray(x + 3)))
                lvi.SubItems.Add(link(Trim(dataArray(x + 6))))
                lstDuplicates.Items.Add(lvi)
            End If
            x += 9
        Loop

This doesn't work, and tells me the result can't be indexed. I haven't worked with adding hyperlinks before to a listview. Any help would be welcomed.

Thanks,

Soul Pumpkin
 
I'm using VB, not ASP. I'm guessing from your response though, that I can't do this?

I'll look over there as well. Thanks.

Soul Pumpkin
 
Oh, heh, mybust. I missread. Sorry, I'm just getting used to auto responding to ASP.Net questions ;)

I would create a datatable that contains the hyperlink text, and the actualy HREF. catch the onclick event of the list box, grab the record they clicked, and use system.diagnostics.process.start(HREF) to open the default browser to the link.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
That is awesome man. Thanks, I've been working on this thing for awhile now.

Thanks again,


Soul Pumpkin
 
Rick

Is there a way you can underline the text in the listview so that you can give it the "look and feel" of a normal hyperlink? I know you can change the color of the text as well as the mouse icon, but it would be really nice if the text could be underlined as well.

Thanks,

-lucyv
 
soulpumpkin and lucyv, you might want to have a look at the Glacial list view control - very powerful, flexible and easy to use and should easily do what both of you want.

The free version 1.3 is available from here:


(ignore the c# code - just use the control) or you can buy the latest version from their website:


The free version lets you specify the object type for a column, easy formatting of items and has an ItemClicked event, plus lots more.


Hope this helps.
 
Actually, the link I needed was to open a file local to disk. I didn't need to open browser or any, but I ended up using the system.diagnostics.process.start() and passing the full path of the file. Here is the code that is working now:
Code:
Private Sub lstDuplicates_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDuplicates.SelectedIndexChanged
        System.Diagnostics.Process.Start(lstDuplicates.SelectedItems.Item(0).SubItems.Item(2).Text)
    End Sub

Thanks alot Rick. It was simple, and works great.

Soul Pumpkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top