Re: Common dialog control returns wrong filename

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 09/29/04


Date: Wed, 29 Sep 2004 18:42:00 -0400

This is not a "bug" in VB, but rather an "issue" particular to Windows
common dialogs. It is caused by the listview generating a CDN_SELCHANGE
message when the listview area is clicked. When a white space is clicked the
highlighting is removed from the current selection, causing the
CDN_SELCHANGE message. I suspect code responding to the CDN_SELCHANGE
message interrogates the listview as to its currently-selected item
returning the name of the previously selected item. This is not a bug per
se, but rather the way a listview works. For example, in a VB application
utilizing a listview, querying the Selected property will indicate that an
item has been selected when the listview is first loaded, even if the user
has not actually done so.

Remember too that Word and Excel do not use the Windows common dialogs, so
their custom implementation to duplicate the functionality of the real
common dialogs may circumvent the problem. I suggest you try the same test
with Notepad, Paint, or any other Windows or third-party application that
uses the real common dialogs.

-- 
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Norman Diamond" <ndiamond@nospam.nospam> wrote in message
news:2AF9BB59-EAE5-413F-B975-FC9901C42FA3@microsoft.com...
: In VB6 SP6, VB6 SP5, and possibly others, the common dialog box sometimes
: returns a different filename from the name that is displayed on the
filename
: line.
:
: Write a small program that opens a common dialog box for saving a file.
: When executed, the dialog box shows a list of files presently existing in
the
: directory.  Do a single click on one filename and the filename is
: automatically copied to the filename line in the dialog box.  Edit the
name
: on the filename line to a nonexistent file, as if you want to save a new
file
: with a slightly different name instead of overwriting the existing file.
:
: Now, if you don't want to see the bug occur, then click immediately on the
: Save button.
:
: But if you do want to see the bug occur, for example if your customer
: complains that your program overwrote their valuable data and you need to
: prove whose fault it is, then you do the following instead.  After
slightly
: editing the name in the filename line, click a blank spot inside the list
of
: filenames in the main part of the common dialog box.  This wasted click
does
: not select a file.  The name shown on the filename line remains as you
edited
: it, it does not automatically change.  Then click on the Save button.  The
: common dialog control returns to your program a filename of an existing
file
: instead of the new name that you put on the filename line.  Your program
will
: destroy your customer's existing data.
:
: My boss just did similar tests with Microsoft Word, Excel, and other
: applications.  They do not have this bug.  Only VB programs get hit by
this
: bug.

Quantcast