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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Items in Listbox - Hyperlink

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm trying to figure out how to make the items in a listbox be a hyperlink. meaning once I fill the listbox, I would like to give the option for the user to click an item in the listbox and that would link to detail about that item. Been searching but can't seem to find anything.

Any help would be appreciated.

Thanks

 
By hyperlink, do you mean an actual " link to a web resource, or do you have a datasource for the listbox and a datasource for the details and you want the appropriate detail to be shown when an item in the listbox is clicked?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Yeah, so when the user clicked item 123456 inside the listbox, I would like to open another form which contains detail about item 123456

 

You can do something like this:

dtItems - the items datatable, has ItemName and ItemID
ListBox1 - the listbox for displaying the items

'assign the dtItems table to the listbox
ListBox1.DisplayMember = "ItemName"
ListBox1.ValueMember = "ItemID"

Next, set up the SelectedIndexChanged event for the listbox:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim ThisItemID As String = ""

ThisItemID = ListBox1.SelectedValue

'now that you have the ItemID for the selected item, there are a number of ways to display the details
'assume a separate form called frmDetails, with a Public property called ItemID:

Dim fDetails As frmDetails

fDetails.ItemID = ThisItemID

fDetails.ShowDialog()

End Sub

Now, in frmDetails you would do this:

'first, create the Public property for ItemID
Dim sItemID As String = ""

Public Property ItemID() As String
Get
Return sItemID
End Get
Set(ByVal value As String)
sItemID = value
End Set
End Property

Now, in the form's Load event, get the details data:

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

Dim SQLStr As String = "Select * from tblDetails where ItemID='" & sItemID & "'" 'use the appropriate table name

'execute the SQL and display the result

End Sub

Hope this helps.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
i'm getting fDetails is used before it's assigned a value

Dim fDetails As frmDetails

fDetails.ItemID = ThisItemID

fDetails.ShowDialog()


 
Oops, sorry. You need to instantiate an instance of frmDetails first. Corrected below:

Dim fDetails As frmDetails

[red]fDetails = New frmDetails[/red]

fDetails.ItemID = ThisItemID

fDetails.ShowDialog()

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
okay, thanks, that worked.... before running the select from the DB, I wanted to make sure the correct value was being passed to frmDetails. I created a textbox on frmDetails and was trying to fill it in the the value selected from the listbox. the form opens with no errors but the textbox stays blank....

Public Class frmDetails

Dim sItemID As String = ""

Public Property ItemID() As String
Get
Return sItemID
End Get
Set(ByVal value As String)
sItemID = value
End Set
End Property

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

t1.Text = sItemID

End Sub



 

Put a message box in the listbox's SelectedIndexChanged event handler, to display ThisItemID, to make sure that is working properly.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top