jxharding
asked on
pls help create array of linklabels to be added to form, and when click on linklabel, it opens the filename of the linklabel
hi, i have not before dynamically created arrays of controls.
could someone please help me with this, i have included all the code i have done so far.
the idea is that a dataset contains 10 entries.
for each entry , i want to dynamically add a linklabel to the form, with the text of the filename.
and when the user clicks on the filename, it must open.
thats it.
this will be a learning curve for me.
here is my code so far.
please just create a strongly typed dataset called dataset1
and add a element "FilesCreated"
with a row "FileName"
'------------------------- ---------- ---------- ---------- ---------
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents HeadingLabel As System.Windows.Forms.Label
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkL abel
Friend WithEvents Dataset11 As DisplayFileNamesLink.Datas et1
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.HeadingLabel = New System.Windows.Forms.Label
Me.LinkLabel1 = New System.Windows.Forms.LinkL abel
Me.Dataset11 = New DisplayFileNamesLink.Datas et1
CType(Me.Dataset11, System.ComponentModel.ISup portInitia lize).Begi nInit()
Me.SuspendLayout()
'
'HeadingLabel
'
Me.HeadingLabel.Location = New System.Drawing.Point(0, 0)
Me.HeadingLabel.Name = "HeadingLabel"
Me.HeadingLabel.Size = New System.Drawing.Size(168, 23)
Me.HeadingLabel.TabIndex = 0
Me.HeadingLabel.Text = "Label1"
'
'LinkLabel1
'
Me.LinkLabel1.Location = New System.Drawing.Point(0, 32)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.TabIndex = 1
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = "LinkLabel1"
'
'Dataset11
'
Me.Dataset11.DataSetName = "Dataset1"
Me.Dataset11.Locale = New System.Globalization.Cultu reInfo("en -US")
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.LinkLab el1)
Me.Controls.Add(Me.Heading Label)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Dataset11, System.ComponentModel.ISup portInitia lize).EndI nit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AddFileNameToList(ByVal FullPath As String)
Dim NewFileCreated As Dataset1.FilesCreatedRow = Dataset11.FilesCreated.New FilesCreat edRow
NewFileCreated.FileName = FullPath
Dataset11.FilesCreated.Add FilesCreat edRow(NewF ileCreated )
End Sub
Private Sub DisplayAllFilesCreated()
'Dim HeadingLabel As Label
HeadingLabel.Text = "The Following Files Have Been Created : "
Dim myLabel() As LinkLabel
Dim i As Integer
For i = 0 To Dataset11.FilesCreated.Cou nt
'create a new linklabel
'set linklabel's height to be = linklabel(i -1).top + linklabel(i -1).height
myLabel(i).Text = Dataset11.FilesCreated(i)( 0).ToStrin g
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 9
AddFileNameToList("C:\F" & i.ToString & ".txt")
Next
DisplayAllFilesCreated()
End Sub
Private Sub LinkLabel1_LinkClicked(ByV al sender As System.Object, ByVal e As System.Windows.Forms.LinkL abelLinkCl ickedEvent Args) Handles LinkLabel1.LinkClicked
End Sub
End Class
'-----------------thanks!
could someone please help me with this, i have included all the code i have done so far.
the idea is that a dataset contains 10 entries.
for each entry , i want to dynamically add a linklabel to the form, with the text of the filename.
and when the user clicks on the filename, it must open.
thats it.
this will be a learning curve for me.
here is my code so far.
please just create a strongly typed dataset called dataset1
and add a element "FilesCreated"
with a row "FileName"
'-------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents HeadingLabel As System.Windows.Forms.Label
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkL
Friend WithEvents Dataset11 As DisplayFileNamesLink.Datas
<System.Diagnostics.Debugg
Me.HeadingLabel = New System.Windows.Forms.Label
Me.LinkLabel1 = New System.Windows.Forms.LinkL
Me.Dataset11 = New DisplayFileNamesLink.Datas
CType(Me.Dataset11, System.ComponentModel.ISup
Me.SuspendLayout()
'
'HeadingLabel
'
Me.HeadingLabel.Location = New System.Drawing.Point(0, 0)
Me.HeadingLabel.Name = "HeadingLabel"
Me.HeadingLabel.Size = New System.Drawing.Size(168, 23)
Me.HeadingLabel.TabIndex = 0
Me.HeadingLabel.Text = "Label1"
'
'LinkLabel1
'
Me.LinkLabel1.Location = New System.Drawing.Point(0, 32)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.TabIndex = 1
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = "LinkLabel1"
'
'Dataset11
'
Me.Dataset11.DataSetName = "Dataset1"
Me.Dataset11.Locale = New System.Globalization.Cultu
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.LinkLab
Me.Controls.Add(Me.Heading
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.Dataset11, System.ComponentModel.ISup
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AddFileNameToList(ByVal FullPath As String)
Dim NewFileCreated As Dataset1.FilesCreatedRow = Dataset11.FilesCreated.New
NewFileCreated.FileName = FullPath
Dataset11.FilesCreated.Add
End Sub
Private Sub DisplayAllFilesCreated()
'Dim HeadingLabel As Label
HeadingLabel.Text = "The Following Files Have Been Created : "
Dim myLabel() As LinkLabel
Dim i As Integer
For i = 0 To Dataset11.FilesCreated.Cou
'create a new linklabel
'set linklabel's height to be = linklabel(i -1).top + linklabel(i -1).height
myLabel(i).Text = Dataset11.FilesCreated(i)(
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 9
AddFileNameToList("C:\F" & i.ToString & ".txt")
Next
DisplayAllFilesCreated()
End Sub
Private Sub LinkLabel1_LinkClicked(ByV
End Sub
End Class
'-----------------thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi idle_mind
do you perhaps know of a way that i can modify the linklabel_linkclicked event so i can always open the file with wordpad?
Try
System.Diagnostics.Process .Start(e.L ink.LinkDa ta)
Catch ex As Exception
MsgBox(ex.Message)
End Try
thanks!
do you perhaps know of a way that i can modify the linklabel_linkclicked event so i can always open the file with wordpad?
Try
System.Diagnostics.Process
Catch ex As Exception
MsgBox(ex.Message)
End Try
thanks!
Sure use this instead:
Process.Start("WordPad.exe ", e.Link.LinkData)
~IM
Process.Start("WordPad.exe
~IM
ASKER
excellent, thanks again!
ASKER
thanks a million idle_mind