473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

OpenFileDialog - how to select files by coding???

I’m using OpenFileDialog class in a specific InitialDirectory and I want that
files will be selected in the opened dialog when I call ShowDialog().
Actually I wish to select all files in the directory automatically by code.

Is it doable?
How??

--
Regards
Sharon G.
Nov 16 '05 #1
4 8605
Sharon,

I don't believe that this is possible. You might be able to hack it by
getting the window handle for the file dialog and then getting the handle
for the listview, and then sending the message to select every item, but
that would seem excessive.

Does the possibility exist that only some files in the directory would
be selected, or will they always be selecting all of the files in the
directory? If it is the latter, then you might want to consider using a
DirectoryBrowseDialog (I believe that is what it is called), as it will let
you select directories.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
I'm using OpenFileDialog class in a specific InitialDirectory and I want
that
files will be selected in the opened dialog when I call ShowDialog().
Actually I wish to select all files in the directory automatically by
code.

Is it doable?
How??

--
Regards
Sharon G.

Nov 16 '05 #2
Sharon,

When you want to have all files why are you than using OpenFileDialog and
not just

DirectoryInfo
http://msdn.microsoft.com/library/de...snametopic.asp

A sample to get those filenames is in this link.

I hope this helps?

Cor
Nov 16 '05 #3
Eventually I'm using the native API FindWindow() ans SendMessge(), but I can
find what message to send to the Form.ListBox.
Can anybody tell me how to complete and fix the following call so the
ListBox will select all files in it?

SendMessage(listviewHandle, 0x0111, ...

I already obtained the listviewHandle but all other parameters are missing
for me, especially I need the actual value of the message, like 0x702e for
Tiles view.

Nov 16 '05 #4
Ok, I have the answer:

[DllImport("user32.dll", EntryPoint="SendMessageA",
CallingConvention=CallingConvention.StdCall,CharSe t=CharSet.Ansi)]
private static extern uint SendMessage(uint Hdc, uint Msg_Const, uint
wParam, uint lParam);

[DllImport("user32.dll", EntryPoint="FindWindowExA",
CallingConvention=CallingConvention.StdCall,CharSe t=CharSet.Ansi)]
private static extern uint FindWindowEx(uint hwndParent, uint
hwndChildAfter, string lpszClass, string lpszWindow);

protected override void WndProc(ref Message m)
{
// Leting the Form take care off all messages.
base.WndProc(ref m);

if( m.Msg == 289 ) // Notify of message loop
{
uint dialogHandle = (uint)m.LParam; // Handle of the file dialog

if( dialogHandle != m_lastDialogHandle ) // Only when not already changed
{
// Getting the handle of the ListBox in the OpenFileDialog dialog.
uint listviewHandle = FindWindowEx(dialogHandle, 0,
"SHELLDLL_DefView", "");

// Sending message to the ListBox to set the view to Thumbnails
//Icons=0x7029, List=0x702b, Details=0x702c, Thumbnails=0x702d,
Tiles=0x702e
SendMessage(listviewHandle, 0x0111/*WM_COMMAND*/, (uint)0x702d, 0);

// Sending message to the ListBox to select all items.
SendMessage(listviewHandle, 0x0111/*WM_COMMAND*/, (uint)0x00017021,
(uint)0);

// Remember last handle
m_lastDialogHandle = dialogHandle;
}
}
}
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Winfree | last post by:
Hi all, i have made a page with several photos of a party. There is a index in the page, and under each thumbnail there is a checkbox. With them people can select the photos that he's going to...
11
by: Mr. B | last post by:
If you can set the 'initial' path of an OpenFileDialog box by something like the following: Dim FilesPath As String ' Files Path FilesPath = "P:\Projects\" FilesPath =...
2
by: Piotrek Stachowicz | last post by:
Hi, Is there any way how can I select more than 1 file in the OpenFileDialog?! It would be really greate if I could also select a directory, click open, and recevice all the files in that...
1
by: Jan | last post by:
Hi there, I have the following problem: Is there a way to select files on time or date. I mean on the time that they are saved. I have a lot of files with a certain save time/date. Thx
4
by: Chuck Edgeworth | last post by:
I'm trying to be able to select a combination of files and folders. When I try to use the OpenFileDialog it will allow me to select them but when I press the Open button it only informs me of the...
0
by: =?Utf-8?B?V2lsbGlhbSBGb3N0ZXI=?= | last post by:
Good evening all, I was wondering if anyone knows how to exclude files from an OpenFileDialog object; for example if I want to find all *.TXT files except those starting with A; usually to find...
0
by: Baileyboo936 | last post by:
Hi I am looking for some help with my code. I am very new to Visual Basic .Net. What I am trying to do is have a button that will allow me to select the directory and the files that I want to...
2
by: Daveryaaziem | last post by:
This is what I am looking for. So I will basically have two databases. One with the questions and one with the answers. Each database will have several tables. For example questions in database 1...
1
by: Deepak Ethiraja | last post by:
For a basic application developed in VB.NET, I used the OpenFileDialog to browse and select a file. For some unknown reason, I'm unable to get the auto-populate file list work on Windows XP SP 3...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.