|
-
Dec 5th, 2006, 08:08 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Problem with link labels
Hi guys,
I am creating several link labels at runtime. I am using the following code:
VB Code:
'Get all questions with matching qID and create linklabels for each.
For j As Integer = 0 To PhotoPicker.arrQuestion.Length - 2
If PhotoPicker.arrQuestion(j).qID = questionnaireID Then
lnk_Question = New LinkLabel
With lnk_Question
.Text = PhotoPicker.arrQuestion(j).question.ToString
.Top = PhotoPicker.pnl_Questions.Top + (count * 35)
.Width = PhotoPicker.pnl_Questions.Width - 25
.Height = 30
.Left = PhotoPicker.pnl_Questions.Left + 10
.Parent = PhotoPicker.pnl_Questions
AddHandler lnk_Question.Click, AddressOf lnk_Question_click
End With
PhotoPicker.pnl_Questions.Controls.Add(lnk_Question)
count += 1
End If
Next
Now the link labels display fine but when i click on a link label i need to compare the text of the link label to an array and return the element number. Now when i actually click on any link label it returns the text of the last link label created.
Can anybody tell me why it is doing this and how i can get around it?
Thanks in advance for any help

(I am using .net compact framework -> but i dont think that will make a difference to how to tackle this problem.)
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 5th, 2006, 08:17 AM
#2
Re: Problem with link labels
Please show your code in the button click event
-
Dec 5th, 2006, 08:21 AM
#3
Thread Starter
Fanatic Member
Re: Problem with link labels
There is no button, its a link label
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 5th, 2006, 08:30 AM
#4
Re: Problem with link labels
I'll wager that in your Click event handler you're referring to the 'lnk_Question' variable, which of course is going to refer to the last control created. As for every event handler, the 'sender' argument is a reference to the object that raised the event. As always, it will be type Object, so you need to cast it as type LinkLabel.
Also, the Click event of the LinkLabel class should rarely be used. That event is raised when the user clicks anywhere within the region of the control, which is rarely what you want from a LinkLabel. You should be handling the LinkClicked event.
-
Dec 5th, 2006, 08:37 AM
#5
Re: Problem with link labels
 Originally Posted by Kimmy4
There is no button, its a link label
Opss... Sorry. I meant the LinkLabel click event
-
Dec 5th, 2006, 09:01 AM
#6
Thread Starter
Fanatic Member
Re: Problem with link labels
Here's my code for the .click event.
Thanks both for the reply.
VB Code:
Private Sub lnk_Question_click(ByVal sender As Object, ByVal e As System.EventArgs)
For k As Integer = 0 To PhotoPicker.arrQuestion.Length - 2
If lnk_Question.Text = PhotoPicker.arrQuestion(k).question Then
MsgBox(lnk_Question.Text.ToString)
End If
Next
End Sub
I understand what you're saying jmcilhinney. I just dont know how to change the code i already have accordingly. Could either of you provide some examples for me.
Thanks again.
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 5th, 2006, 09:13 AM
#7
Re: Problem with link labels
There's no need to add a string variable like I've done but it would be something like this I think in order to cast which link label it refers to:
VB Code:
Private Sub lnk_Question_click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myString As String = DirectCast(sender, LinkLabel).Text
For k As Integer = 0 To PhotoPicker.arrQuestion.Length - 2
If myString = PhotoPicker.arrQuestion(k).question Then
MsgBox(myString)
End If
Next
End Sub
I haven't tried this but you should get the idea of how the cast works and get it to hopefully work from this.
-
Dec 5th, 2006, 09:36 AM
#8
Thread Starter
Fanatic Member
Re: Problem with link labels
Thanks i'll try it out and let you know how i get on.
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 5th, 2006, 09:40 AM
#9
Thread Starter
Fanatic Member
Re: Problem with link labels
Works perfectly. I didn't assign to a string first. I just put
VB Code:
If directCast(sender, linklabel).text = PhotoPicker.arrQuestion(k).question Then
Thanks for the help.
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Dec 5th, 2006, 09:43 AM
#10
Re: [RESOLVED] Problem with link labels
That's fine, I was just using the string variable as an example.
-
Apr 19th, 2007, 09:28 AM
#11
New Member
Re: [RESOLVED] Problem with link labels
How can I use PhotoPicker in my website to upload photos, any idea?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|