Add selected file to ListBox : ListBox « Windows Presentation Foundation « VB.Net Tutorial






<Window x:Class="Windows.OpenFileTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="OpenFileTest" Height="300" Width="300" 
    >
  <DockPanel Margin="5">
    <Button DockPanel.Dock="Top" Click="cmdOpen_Click">Open</Button>
    <ListBox Name="lstFiles"></ListBox>
  </DockPanel>
</Window>
//File:Window.xaml.vb

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Imports Microsoft.Win32

Namespace Windows
  Public Partial Class OpenFileTest
    Inherits System.Windows.Window
    Public Sub New()
      InitializeComponent()
    End Sub

    Private Sub cmdOpen_Click(sender As Object, e As RoutedEventArgs)
      Dim myDialog As New OpenFileDialog()

      myDialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
      myDialog.CheckFileExists = True
      myDialog.Multiselect = True

      If myDialog.ShowDialog() = True Then
        lstFiles.Items.Clear()
        For Each file As String In myDialog.FileNames
          lstFiles.Items.Add(file)
        Next
      End If
    End Sub
  End Class
End Namespace
WPF Add Selected File To List Box








16.27.ListBox
16.27.1.Bind String Array Resource to ListBoxBind String Array Resource to ListBox
16.27.2.Use Data Templates to Display Bound DataUse Data Templates to Display Bound Data
16.27.3.CheckBox ListCheckBox List
16.27.4.Convert the contents of a ListBoxItem to an instance of GridLength by using GridLengthConverterConvert the contents of a ListBoxItem to an instance of GridLength by using GridLengthConverter
16.27.5.Use the FontSizeConverter class to convert the content of a ListBoxItem to a value that represents the size of a font.Use the FontSizeConverter class to convert the content of a ListBoxItem to a value that represents the size of a font.
16.27.6.Convert contents of a ListBoxItem to an instance of Thickness by using the ThicknessConverterConvert contents of a ListBoxItem to an instance of Thickness by using the ThicknessConverter
16.27.7.DataTrigger, ListBox and user objectDataTrigger, ListBox and user object
16.27.8.Add selected file to ListBoxAdd selected file to ListBox
16.27.9.This list box allows items to be selected in groups by using the SHIFT key and mouse or the CTRL key and space key.This list box allows items to be selected in groups by using the SHIFT key and mouse or the CTRL key and space key.
16.27.10.Iterate through the selected items and remove each oneIterate through the selected items and remove each one
16.27.11.Ensure there is at least one item selectedEnsure there is at least one item selected