Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click Dim x As String x = DirectCast(sender, ListBox).SelectedItem End Sub
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' End Sub 'Private Sub ReadFile() 'Dim You As String Dim listitems As New List(Of String) Dim pathfichier As String 'You = FreeFile() 'Dim List1 As New ListBox ' Create an instance of the ListBox. Dim listBox1 As New Windows.Forms.ListBox() ' Set the size and location of the ListBox. listBox1.Size = New System.Drawing.Size(209, 103) listBox1.Location = New System.Drawing.Point(-2, 86) ' Add the ListBox to the form. Me.Controls.Add(listBox1) ' Set the ListBox to display items in multiple columns. listBox1.MultiColumn = True ' Set the selection mode to multiple and extended. 'listBox1.SelectionMode = SelectionMode.MultiExtended ' Shutdown the painting of the ListBox as items are added. listBox1.BeginUpdate() 'le chemin du fichier pathfichier = "E:Modif.TXT" 'je lis tout le fichier dans listitems Try listitems = System.IO.File.ReadAllLines(pathfichier).ToList Catch ex As Exception 'MessageBox.Show() 'MsgBox(listitems) End Try 'copier à partir de la 3 ligne attention la premiere est indexée par 0 For iter = 2 To listitems.Count - 1 listBox1.Items.Add(listitems(iter)) ' Allow the ListBox to repaint and display the new items. listBox1.EndUpdate() 'listBox1.SetSelected(0, True) 'System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems(1).ToString(You)) Next 'Dim Boy As String = "aaa" 'Boy = listBox1.SelectedItem End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click Dim x As String x = DirectCast(sender, ListBox).SelectedItem End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim listBox1 As New Windows.Forms.ListBox() Dim Boy As String = "aaa" Boy = listBox1.SelectedItem 'listBox1.SelectedItem.ToString(Boy) 'Dim curItem As String = listBox1.SelectedItem.ToString() 'listBox1.SelectedValue.ToString(Boy) MsgBox(Boy) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionEn ait je la crée en runtime car j'arrive pas à afficher son contenu en IDE
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' End Sub 'Private Sub ReadFile() 'Dim You As String Dim listitems As New List(Of String) Dim pathfichier As String 'You = FreeFile() 'Dim List1 As New ListBox ' Create an instance of the ListBox. Dim listBox1 As New Windows.Forms.ListBox() ' Set the size and location of the ListBox. 'listBox1.Size = New System.Drawing.Size(209, 103) 'listBox1.Location = New System.Drawing.Point(-2, 86) ' Add the ListBox to the form. 'Me.Controls.Add(listBox1) ' Set the ListBox to display items in multiple columns. listBox1.MultiColumn = True ' Set the selection mode to multiple and extended. 'listBox1.SelectionMode = SelectionMode.MultiExtended ' Shutdown the painting of the ListBox as items are added. listBox1.BeginUpdate() 'le chemin du fichier pathfichier = "E:Modif.TXT" 'je lis tout le fichier dans listitems Try listitems = System.IO.File.ReadAllLines(pathfichier).ToList Catch ex As Exception 'MessageBox.Show() 'MsgBox(listitems) End Try 'copier à partir de la 3 ligne attention la premiere est indexée par 0 For iter = 2 To listitems.Count - 1 listBox1.Items.Add(listitems(iter)) ' Allow the ListBox to repaint and display the new items. listBox1.EndUpdate() 'listBox1.SetSelected(0, True) 'System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems(1).ToString(You)) Next 'Dim Boy As String = "aaa" 'Boy = listBox1.SelectedItem End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim x As String x = DirectCast(sender, ListBox).SelectedItem MsgBox(x) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Dim listBox1 As New Windows.Forms.ListBox() 'Dim Boy As String = "aaa" 'Boy = listBox1.SelectedItem 'listBox1.SelectedItem.ToString(Boy) 'Dim curItem As String = listBox1.SelectedItem.ToString() 'listBox1.SelectedValue.ToString(Boy) 'MsgBox(Boy) End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged End Sub End Class
Dim listBox1 As New Windows.Forms.ListBox()