pick up a FOLDER with a nice explorer

P

pamela fluente

I want to use the ordinary OpenFileDialog to choose a folder instead
of a file. Is it possible? And how?

[I do not want to use the standard FolderBrowserDialog, because too
ugly and poor for my taste]


-P
 
R

rowe_newsgroups

No, because the OpenFileDialog was not designed to "open" a folder. Now,
having said that, if the FolderBrowserDialog doesn't suit your high-fashion
couture, you are free to derive from it and "soup it up"... ;-)
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

pamela fluente said:
I want to use the ordinary OpenFileDialog to choose a folder instead
of a file. Is it possible? And how?
[I do not want to use the standard FolderBrowserDialog, because too
ugly and poor for my taste]



Recursion: see Recursion

That just made my day :)

Thanks,

Seth Rowe
 
R

rowe_newsgroups

No, because the OpenFileDialog was not designed to "open" a folder. Now,
having said that, if the FolderBrowserDialog doesn't suit your high-fashion
couture, you are free to derive from it and "soup it up"... ;-)
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
I want to use the ordinary OpenFileDialog to choose a folder instead
of a file. Is it possible? And how?
[I do not want to use the standard FolderBrowserDialog, because too
ugly and poor for my taste]
-P
Recursion: see Recursion

That just made my day :)

Thanks,

Seth Rowe

Darn google trimmed my quote again - the "Recursion: see Recursion"
quote is what I was referring to with "made my day"

Thanks,

Seth Rowe
 
P

pamela fluente

On Jul 20, 1:31 pm, rowe_newsgroups <[email protected]> wrote:
Darn google trimmed my quote again - the "Recursion: see Recursion"
quote is what I was referring to with "made my day"


That would be a nice quote, except for the fact that is an infinite
loop, not a recursion.

(That's always my "high-fashion couture")

-P
 
O

\(O\)enone

Peter said:
No, because the OpenFileDialog was not designed to "open" a folder.

There's something that looks suspiciously like it that *is* designed to
select a folder though. In VS2005, open the Tools/Options window, select the
root "Projects and Solutions" tree node and then click the "..." button next
to one of the location boxes at the top of the dialog. That definitely looks
like the OpenFileDialog to me, and it's selecting a folder rather than a
file.

Can the OpenFileDialog do that? I must confess I haven't tried it.

(I too find the FolderBrowserDialog quite irritating, not least of which
because you can't type in it, making all selections tedious click-fests and
also making it impossible to select folders via UNC locations).
 
P

pamela fluente

There's something that looks suspiciously like it that *is* designed to
select a folder though. In VS2005, open the Tools/Options window, select the
root "Projects and Solutions" tree node and then click the "..." button next
to one of the location boxes at the top of the dialog. That definitely looks
like the OpenFileDialog to me, and it's selecting a folder rather than a
file.

Can the OpenFileDialog do that? I must confess I haven't tried it.

(I too find the FolderBrowserDialog quite irritating, not least of which
because you can't type in it, making all selections tedious click-fests and
also making it impossible to select folders via UNC locations).

Let's discuss this idea (perhaps a stupid one).

When I explore my folders using the OpenFileDialog there must be some
place where the current folder is recorded.

Can I get that information, from environment or whatever, and return
it when the dialog is closed by the user with OK ?

If one could do that, I think we would have a nice folder browser.

(And actually I do not see why the OpenFileDialog , which is nice,
could not also serve, possibly with appropriate properties, to select
folders. It seems quite stupid to have an additional dialog, an even
an ugly one.)

-P
 
P

pamela fluente

For instance see this:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) _
Handles Button1.Click

Dim MyPath As String = SelectAFolder()

If MyPath IsNot Nothing Then
MsgBox("Path selected is " & MyPath)
End If

End Sub


Function SelectAFolder() As String

Dim SelectedPath As String = Nothing

Using Ofd As New OpenFileDialog
With Ofd
.RestoreDirectory = False 'crucial

If .ShowDialog() Then
SelectedPath = Environment.CurrentDirectory
End If
End With
End Using

Return SelectedPath

End Function

End Class


Now what is missing is just a slight change of behavior of the button
(ok instead of open folder). Then we would have a nice folder browser.

Can we do that ?


-P
 
P

Peter Duniho

There's something that looks suspiciously like it that *is* designed to
select a folder though. In VS2005, open the Tools/Options window, select
the
root "Projects and Solutions" tree node and then click the "..." button
next
to one of the location boxes at the top of the dialog. That definitely
looks
like the OpenFileDialog to me, and it's selecting a folder rather than a
file.

Can the OpenFileDialog do that? I must confess I haven't tried it.

It probably is based on the OpenFileDialog, though I suppose you'd have to
watch it in a debugger to be sure (or ask the guy who wrote it). You
could do something similar by creating a new dialog derived from the
OpenFileDialog and/or the native Win32 common file open dialog, and
overriding the base behavior so that the "Open" button returns with path
and no filename.

But it's a big UI mistake to do that, IMHO. I don't see what the fuss
about the folder browser dialog is. I agree it'd be nice to have better
typing control over the browser, but overloading the file browser to
return folders results in some pretty user-unfriendly behavior.

In the example you describe, contrary to what the user normally expects,
selecting a folder and clicking the "Open" button dismisses the dialog
rather than descending into the directory tree. The fact that the dialog
looks so much like the usual common dialog makes the behavior that much
worse; it should at least be visibly and significantly different from the
standard dialog, to ensure the user understands they are dealing with
something different.

The folder browser dialog makes it very clear that you're doing something
different from choosing a file. The UI is so different, there's no chance
the user will get confused about what button does what.

VS should have used the folder browser in that situation. They've
violated the basic rule of UI: the rule of least surprise.

Pete
 
P

pamela fluente

[...]
Can we do that ?

Do what? Post VB code in a C# newsgroup?

No. You're not allowed to do that.

:)


Should we still really make a difference ?

for the C# readers only: ----------begin---------


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FolderBrowserTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string MyPath = SelectAFolder();
if (MyPath != null)
{
this.Text = "Path selected is " + MyPath;
}
}


public string SelectAFolder()
{
string SelectedPath = null;
using (OpenFileDialog Ofd = new OpenFileDialog())
{
{
Ofd.RestoreDirectory = false;
//crucial

if (Ofd.ShowDialog() == DialogResult.OK )
{
SelectedPath = Environment.CurrentDirectory;
}
}
}

return SelectedPath;
}
}
}


for the C# readers only: ----------end---------

I am still of the opinion that the 2 dialogs should be unified.

Is anybody able to simply change sligtly the behavior of the file
browser ?

-P
 
P

pamela fluente

Peter Bromberg [C# MVP] wrote:

In the example you describe, contrary to what the user normally expects,
selecting a folder and clicking the "Open" button dismisses the dialog
rather than descending into the directory tree.

If this were the difficulty we would be doing a different form for
anything.
Programming is about being general, unifying and reusing.

It's sufficient to have (in browse folder mode) 2 buttons: on to open
and one
to select.

Still do not see the point to create an additional dialog, especially
if it is
quite ugly and irritating to use.

-P
 
P

Peter Duniho

Should we still really make a difference ?

It was a joke. Please note the "emoticon" (aka "smiley") that I posted,
and which you quoted.
[...]
Is anybody able to simply change sligtly the behavior of the file
browser ?

You may be able to override the behavior using the standard C#
mechanisms. If not, then for sure you can override the behavior by using
the WndProc override and handling the various Windows messages. There's
all sorts of things you can do with the common dialogs via this mechanism,
if you really want to.

But read my other post. The point is that people shouldn't be going
around changing the fundamental behaviors of a shared UI element. It's
very bad for the user. If your sense of aesthetics is offended by not
having the same visual thing do different things in different contexts,
then it's your sense of aesthetics that needs fixing, not the UI element.

Pete
 
B

Ben Voigt [C++ MVP]

pamela fluente said:
That would be a nice quote, except for the fact that is an infinite
loop, not a recursion.

It is indeed a recursive definition. And as you say, it is infinitely
recursive. But not all self-referential definitions are infinitely
recursive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top