Control File View from OpenFileDialog?

When I open a choose file dialog from my program, the files are always listed with the LIST view.  Even if I change the view to my personal preference of DETAILS, the next time my program launches the view is set to LIST again.   Is there a way to control the view provided by OpenFileDialog?  


Thanks.
codefingerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nffvrxqgrcfqvvcCommented:
 

There is no way to set specific dialog to a specific view type. Windows has its own internal way of thinking about how the dialog should be displayed. For example if the special folders like My Pictures has registry settings that when the dialog is opened to that special location it automatically changes the view type to Thumbnails view.

You can however directly send a message to the dialog to make it switch views. If you run SPYX and subclass the dialog you can catch which message it sends when you switch views. Then you send this message directly should make it switch to the appropriate view.
SendMessage using WM_COMMAND for the message and the value (&H702D) for wParam. Sends this directly to dialog class SHELLDLL_DefView
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codefingerAuthor Commented:
egl1044,

You are getting just a little outside my coding comfort zone.  

Can you provide a code sample please?

Thanks.

0
nffvrxqgrcfqvvcCommented:
Sure give this a whirl..
 
Example usage:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New OpenFileDialog
dlg.Title = "Open Stuff"
CustomDialogView.SetDialogView(CustomDialogView.ViewFlags.Thumbnails, dlg.Title)
'CustomDialogView.SetDialogView(CustomDialogView.ViewFlags.Thumbnails, dlg.Title, 500)
dlg.ShowDialog()
End Sub

Public Class CustomDialogView
    ' egl1044
    Private Const WM_COMMAND As Integer = &H111
    Private Const DefView_ID As Integer = &H461
    Public Enum ViewFlags
        Icons = &H7029
        List = &H702B
        Details = &H702C
        Thumbnails = &H702D
        Tiles = &H702E
    End Enum
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function SendDlgItemMessage(ByVal hDlg As IntPtr, ByVal nIDDlgItem As Integer, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function
    Public Shared Sub SetDialogView(ByVal flags As ViewFlags, _
                                    ByVal title As String, _
                                    Optional ByVal dueTime As Integer = 1000)
        Dim stateObj As New MyState
        stateObj.Flags = flags
        stateObj.Title = title
        Dim TimerCb As New Timer(New TimerCallback(AddressOf SetDialogViewCallback), _
                                 stateObj, dueTime, Timeout.Infinite)
    End Sub
    Private Shared Sub SetDialogViewCallback(ByVal state As Object)
        Dim stateObj As MyState = DirectCast(state, MyState)
        Dim hWindow As IntPtr = IntPtr.Zero
        hWindow = FindWindow(Nothing, stateObj.Title)
        If hWindow.ToInt32 <> 0 Then
            SendDlgItemMessage(hWindow, DefView_ID, WM_COMMAND, _
                               New IntPtr(stateObj.Flags), IntPtr.Zero)
        End If
    End Sub
    Private Class MyState
        Public Title As String
        Public Flags As ViewFlags
    End Class
End Class

Open in new window

0
codefingerAuthor Commented:
Hard to believe one has to work so hard to accomplish such a simple result.   Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.