Sabtu, 31 Desember 2011

Multi Select File di Common Dialog

Berikut ini adalah tips bagaimana agar user dapat memilih beberapa file sekaligus dalam kotak dialog.

[ VB 6.0 ]
Buat Form baru dan tambakan didalamnya 1 CommandButton, 1 ListBox, dan 1 CommonDialog (Microsoft Common Dialog Control). Lalu di bagian 'Command1_Click' ketikkan :
On Error GoTo Ero
Dim sFile() As String, i As Integer

With CommonDialog1
.FileName = ""
.CancelError = True
.MaxFileSize = 30000
.Flags = cdlOFNExplorer + cdlOFNAllowMultiselect + cdlOFNHideReadOnly
.ShowOpen

sFile = Split(.FileName, vbNullChar)

List1.Clear 'meghapus isi listbox

If UBound(sFile) = 0 Then 'jika hanya 1 file yang dipilih
List1.AddItem sFile(0)
Else 'jika lebih dari 1 file yang dipilih
For i = 1 To UBound(sFile)
List1.AddItem Replace(sFile(0) & "\" & sFile(i), "\\", "\")
Next
End If

End With

Ero:


[ VB .NET ]
Buat Form baru dan tambakan didalamnya 1 Button, 1 ListBox, dan 1 OpenFileDialog. Lalu di bagian 'Button1_Click' ketikkan :
Dim i As Integer
With OpenFileDialog1
.Multiselect = True
.FileName = ""

If .ShowDialog = 1 Then
ListBox1.Items.Clear() 'meghapus isi listbox

For i = 0 To UBound(.FileNames)
ListBox1.Items.Add(.FileNames(i)) 'memasukkan ke listbox
Next
End If
End With


Source Putravb

Artikel Terkait


EmoticonEmoticon