473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Create An Event For Created LinkLabels

Hello, I was wondering if anyone can help me. I have some code where I'm
creating linklabels during runtime using filenames that in a directory. I
created a LinkClicked event but it only launches the last file that is called
in the ClickEvent. I tried placing the Event in the FOR EACH statement but
that's not helping. If interested I'm using VB2005. How can I apply a Click
Event to each LinkLabel or each linklabel to the same ClickedEvent? Can
someone help? Here is the code:

Dim mLinkLabel As LinkLabel 'declared globally

Private Sub CreateLinkLabels(ByRef strDirectory As String)
Dim strTmp, strFile As String
<Other variable declarations>

For Each strFile In Directory.GetFiles(strDirectory) 'grab each file
in the directory
If Path.GetExtension(strFile).ToLower = ".doc" Or
Path.GetExtension(strFile).ToLower = ".pdf" Then
strTmp = Path.GetFileName(strFile)
mLinkLabel = New LinkLabel

With mLinkLabel
.Name = "lnkLabel_" & i.ToString()
.Visible = True
.ActiveLinkColor = Color.Red
.DisabledLinkColor = Color.Blue
.LinkColor = Color.Blue
.VisitedLinkColor = Color.Purple
.Size = New System.Drawing.Size(intWidth, intHeight)
.Location = New System.Drawing.Point(intX, intY *
intIncrement)
.Text = strTmp
End With

AddHandler mLinkLabel.LinkClicked, AddressOf
mLinkLabel_LinkClicked 'addhandler for click event.
intNum += 1
intIncrement += 2

'Add the linkLabels to the panel control.
plMain.Controls.Add(mLinkLabel)

End If
i += 1
Next
tsText.Text = intNum.ToString() & " Files"
End Sub

Private Sub mLinkLabel_LinkClicked(ByVal sender As Object, ByVal e As
LinkLabelLinkClickedEventArgs) 'Handles myLinkLabel.LinkClicked

Dim lnk As LinkLabel = New LinkLabel

lnk = CType(sender, LinkLabel)

lnk.Links(lnk.Links.IndexOf(e.Link)).Visited = True

System.Diagnostics.Process.Start("C:\Documents and Settings
Documents\test\" & mLinkLabel.Text)

End Sub
--
TC
Apr 13 '06 #1
0 1104

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Patrick Marti | last post by:
I wish to create some LinkButtons in DotNet. Because I will do it in dependence of the entries in a database, I can not add them with the mouse to the form as usually. I can create them in the...
0
by: HamuNaptra | last post by:
Hi, I have a form which contains more than 15 linklabels, all of them have a transparant backcolor. The form itself has a backgroundimage. Now when I show the form, it takes a moment to...
0
by: Wajih | last post by:
I have a list view. I want to insert LinkLabels dynamically in it as ListViewSubItems. Is it possible to do this? If yes, how should i do it. If no, are there any workarounds. Thanx and regards
0
by: Andrea | last post by:
Hallo, i create controls dynamically on my webproject. most of the controls i create in the oninit-event and all worked wunderfull, but in the event-handling, e.g. the click-event of a button, i...
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
1
by: Terrance | last post by:
I have a problem I was hoping someone can help me with. My first problem is moving a link label that is created at runtime to the of an arraylist on the next line in the listbox. Currently, the...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.