Jag skulle vilja att man kan välja flera filer Hej menar du att man med hjälp av common dialog ska välja Hej okej, men du har inte den direkta lösningen på mitt problem. Hej jag tar mer än gärna mot ditt exempel.. om du vill maila det kan du maila det till paake@telia.com Det går att markera flera filer i CommonDialogs. Här är ett exempel:common dialog problem
när jag öppnar common dialog. Jag vill att
alla filer man väljer hamnar i en listbox.
Någon som vet hur man gör för att välja
flera filer i commondialog box?Sv: common dialog problem
Då tycker jag att du skall använder en FileListBox i kombination
med CommonDialog, och sätt FileListBox till MultiSelect
mvh
SvenSv: common dialog problem
en katalog. och sedan listas alla filer där i filelistbox?Sv: common dialog problem
Ja det är en väg ,eller så använd DirListBox i kombination
med FileListBox.
mvh
SvenSv: common dialog problem
Det där sättet vet jag ju om, men jag är helst ute efter
att man ska kunna välja fler filer i en common dialog box.Sv: common dialog problem
Om du köper att CommonDialog väljer mapp och
sedan presenterar en FileListBox för MultiSelect så kan du få ett
sådant exempel av mig.
Vad jag vet så finns det ingen Flag som gör att man kan
multiselecta direkt i CommonDialog. Logga in om någon vet
mvh
SvenSv: common dialog problem
Sv: common dialog problem
'Form: Form1
Option Explicit
Private Sub Command1_Click()
Dim Files() As String
Dim Index As Long
On Error GoTo Command1_Click_Err
Files = GetOpenFiles("Markera filer!", , "Iconer (*.ico)|*.ico|All filer (*.*)|*.*", 1, Me)
List1.Clear
For Index = LBound(Files) To UBound(Files)
List1.AddItem Files(Index)
Next
Command1_Click_Exit:
Exit Sub
Command1_Click_Err:
Select Case Err.Number
Case 18
'Msgbox "Du valde avbryt!"
Resume Command1_Click_Exit
Case Else
MsgBox Err.Description, vbCritical
Resume Command1_Click_Exit
End Select
End Sub
'Module: Module1
Option Explicit
'Public Const CDERR_FINDRESFAILURE = &H6
'Public Const CDERR_INITIALIZATION = &H2
'Public Const CDERR_LOCKRESFAILURE = &H8
'Public Const CDERR_LOADRESFAILURE = &H7
'Public Const CDERR_LOADSTRFAILURE = &H5
'Public Const CDERR_MEMALLOCFAILURE = &H9
'Public Const CDERR_MEMLOCKFAILURE = &HA
'Public Const CDERR_NOHINSTANCE = &H4
'Public Const CDERR_NOHOOK = &HB
'Public Const CDERR_NOTEMPLATE = &H3
'Public Const CDERR_STRUCTSIZE = &H1
Public Const FNERR_BUFFERTOOSMALL = &H3003
'Public Const FNERR_INVALIDFILENAME = &H3002
'Public Const FNERR_SUBCLASSFAILURE = &H3001
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_EXPLORER = &H80000 ' new look commdlg
Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_READONLY = &H1
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHAREWARN = 0
Private Const OFN_SHOWHELP = &H10
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
'lpstrFile As Long
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long
Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Public Function GetOpenFiles(Optional Title As String, Optional InitialDir As String, Optional Filter As String = "All files (*.*)|*.*", Optional FilterIndex As Long, Optional Owner As Form) As String()
Dim pOpenFileName As OPENFILENAME
Dim Lreturn As Long
Dim sPath As String
Dim sTemp As String
Dim lStart As Long
Dim lLength As Long
Dim Files() As String
Dim Index As Integer
Dim lErrCode As Long
Static Path As String
Const MaxFileLength As Long = 10000
If Owner Is Nothing Then
pOpenFileName.hwndOwner = 0
Else
pOpenFileName.hwndOwner = Owner.hWnd
End If
pOpenFileName.lpstrTitle = Title
pOpenFileName.lpstrFilter = Replace(Filter, "|", vbNullChar) & vbNullChar & vbNullChar
pOpenFileName.nFilterIndex = FilterIndex
pOpenFileName.nMaxFileTitle = MaxFileLength
pOpenFileName.flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT Or OFN_FILEMUSTEXIST Or OFN_LONGNAMES
pOpenFileName.lpstrFile = String$(MaxFileLength, 0)
pOpenFileName.nMaxFile = MaxFileLength
pOpenFileName.lpstrInitialDir = InitialDir
pOpenFileName.lStructSize = Len(pOpenFileName)
Lreturn = GetOpenFileName(pOpenFileName)
If Lreturn = 0 Then
lErrCode = CommDlgExtendedError()
Select Case lErrCode
Case 0
Err.Raise 18 'User interrupt occurred
'Case CDERR_FINDRESFAILURE
'Case CDERR_INITIALIZATION
'Case CDERR_LOCKRESFAILURE
'Case CDERR_LOADRESFAILURE
'Case CDERR_LOADSTRFAILURE
'Case CDERR_MEMALLOCFAILURE
'Case CDERR_MEMLOCKFAILURE
'Case CDERR_NOHINSTANCE
'Case CDERR_NOHOOK
'Case CDERR_NOTEMPLATE
'Case CDERR_STRUCTSIZE
Case FNERR_BUFFERTOOSMALL
Err.Raise FNERR_BUFFERTOOSMALL, GetOpenFiles, "Buffer To Small!"
'Case FNERR_INVALIDFILENAME
'Case FNERR_SUBCLASSFAILURE
Case Else
Err.Raise lErrCode
End Select
'Err.Raise 18 'User interrupt occurred
Else
Path = Left(pOpenFileName.lpstrFile, pOpenFileName.nFileOffset - 1)
If Not Path Like "*\" Then Path = Path & "\"
lStart = pOpenFileName.nFileOffset + 1
lLength = InStr(pOpenFileName.nFileOffset, pOpenFileName.lpstrFile, vbNullChar & vbNullChar, vbBinaryCompare) - lStart
sTemp = Mid(pOpenFileName.lpstrFile, lStart, lLength)
Files = Split(sTemp, vbNullChar, -1, vbBinaryCompare)
For Index = LBound(Files) To UBound(Files)
Files(Index) = Path & Files(Index)
Next
GetOpenFiles = Files
End If
End Function