Results 1 to 7 of 7

Thread: adding links to a listbox [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Resolved adding links to a listbox [RESOLVED]

    I have a program that searches a text file for a particular string and pulls some information to display in a listbox. That information can be used to build a url that I want to display in the listbox.

    This is kind of what I want to do:

    VB Code:
    1. For Each dElement As String In dArray
    2.                     link = "<a href=" + Chr(34) + "http://www.company.com/info.asp?info=" + dElement + Chr(34) + ">" + dElement + "</a>"
    3.                     ListBox1.Items.Add(link)
    4.                 Next

    but it ends up just showing:
    <a href="http://www.company.com/info.asp?info=1234">1234</a>
    rather than have "1234" be a link.

    I've looked at the link class, but when I try to do the "Imports System.Web.UI.MobileControls" the intellisense doesn't know what that is.

    Any ideas on what I'm doing wrong?
    Last edited by shadowfyre; Feb 1st, 2005 at 03:48 PM.

  2. #2
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: adding links to a listbox

    if you want to import System.Web.UI.MobileControls you have to make a reference to the web.dll in your project

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  3. #3
    New Member
    Join Date
    Jan 2005
    Posts
    10

    Re: adding links to a listbox

    Windows form example. It can be easly modified for web site.

    ...
    ' Windows Form Designer generated code

    Dim ok As New SortedList
    Dim okk As DictionaryEntry

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ok.Add("Link 1", "http://www.vbfan.com")
    ok.Add("Link 2", "http://www.microsoft.com")
    For Each okk In ok
    Me.ListBox1.Items.Add(okk.Key)
    Next

    End Sub


    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    Process.Start(okk.Value)

    End Sub
    -------------------------------------------------------------------

    Now, all you have to do is fill values from your text file.
    VBfan.com
    Non english site. Croatian Visual Basic.NET site.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Re: adding links to a listbox

    vbdotnetboy, as per usual, that thought hit me 3 minutes after I hit the post button.

    So now I have:
    VB Code:
    1. For Each da As String In DArray
    2.     defLink.Text = da
    3.     defLink.NavigateUrl = "http://www.company.com/infolog.asp?info=" + da
    4.     ListBox1.Items.Add(defLink)
    5. Next

    Stepping through the code, the attributes get populated correctly, but the listbox displays "System.Web.UI.MobileControls.Link".

    Hmmm... VBnetFan at first I didn't think your idea applied, but now I have an idea. Say that DArray is already sorted and I do:
    VB Code:
    1. For Each da As String In DArray
    2.     ListBox1.Items.Add(da)
    3. Next
    This populates the listbox. Then I could get the selectedindexchanged event to trigger it like this:
    VB Code:
    1. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    2.     Process.Start("http://www.company.com/infolog.asp?info=" + sender.text)
    3. End Sub
    The problem is getting the text of the selected index. Any idea on how to do that?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Re: adding links to a listbox

    Got it, "ListBox1.SelectedItem", Duh!

    VB Code:
    1. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    2.     Process.Start("http://www.company.com/infolog.asp?info=" + ListBox1.SelectedItem)
    3. End Sub

    Thanks guys.

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: adding links to a listbox [RESOLVED]

    just for the record... this is a windows app right??? I think everyone who posted thinks its an ASP.NET app

  7. #7
    Member
    Join Date
    Jan 2005
    Location
    in the nederlands
    Posts
    37

    Talking Re: adding links to a listbox [RESOLVED]

    what is asp.NET ???
    what is xml ???

    help my please on this link for xml
    http://www.vbforums.com/showthread.php?t=322815



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width