Create LinkLabels At Runtime and Configuring the LabelBox

G

Guest

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 Close link is showing up on the
first line and covering up the file names when the box is populated. Here is
the code:

Dim docArray As New ArrayList() 'create an arraylist to hld the documents.
Dim strDirectory = ConfigurationSettings.AppSettings("cad_directory")

Dim objLinkClose As New System.Windows.Forms.LinkLabel 'create new linklabel
With objLinkClose
.Name = "lnkClose"
.Text = "Close"
End With

Dim strFile As String

For Each strFile In Directory.GetFiles(strDirectory) 'get the files
in the directory
If Path.GetExtension(strFile) = ".doc" Or
Path.GetExtension(strFile) = ".pdf" Then
Dim strTemp As String = Path.GetFileName(strFile)
docArray.Add(strTemp)
End If
Next

'If no files are found then inform the user through the listbox.
If docArray.Count() = 0 Then
Dim strTmp As String = "No Files to Display.......!"
docArray.Add(strTmp)
End If
lbdocs.DataSource = docArray
Me.lbdocs.Controls.Add(objLinkClose)

Secondly, I need to make the file names that are returned linklabels also;
so that when a user clicks on one it opens up the file in WORD or PDF(that's
the plan so far). So, any help would greatly be appreciated.
 
G

Guest

Terrance your off to a great start.

search for system.diagnostics.process.start in msdn library. When checking
the file extention add a .tolower to guarantee a match with odd case.
Path.GetExtension(strFile).tolower = ".pdf"

Good Luck
DWS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top