473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8619
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
2084
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
2272
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
1859
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
1537
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
731
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
1045
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
1522
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
2260
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
1765
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
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.