본문 바로가기
스마트 장치 개발

SmartPhone에서 FolderBrowserDialog을 처리하기 위한 방법(DocumentList Control)

by leo21c 2009. 12. 12.
SMALL

WindowsMobileforPocketPC, WindowsMobileforSmartphone

.NETCF does not support FolderBrowserDialog. I agree the docs are confusing (and in error) on this point; If it were supported, under Version Information, you would see an entry for .NET Compact Framework (and the version(s) supported there). I've sent a note to our d0cumentation team to get this issue fixed.

.NETCF does have something similar, the DocumentList control. http://msdn2.microsoft.com/en-us/library/ms172535.aspx. Note, with it, you can only browse to folders under \My Documents.

How to: Use a DocumentList Control

If your application is based on working with files, you can use a DocumentList control to display a customized list of folders and files in the My Documents folder. This is similar to how Microsoft Pocket Word and Microsoft Pocket Excel operate. The control provides the user with the following functionality:

  • Select, delete, copy, move, and rename files and folders.

  • Sort by file name, date, or size.

  • Send files as e-mail attachments.

  • Send files by infrared to another device.

To implement a DocumentList control

  1. Create a Pocket PC Windows application with a DocumentList.

  2. Specify the file types that can be accessed with the Filter property.

  3. Specify the files that are initially displayed with the FilterIndex property.

  4. Specify a default folder with the SelectedDirectory property.

  5. Provide code to handle the DocumentActivated event.

  6. Provide code to handle the DeletingDocument event.

  7. Provide code to handle the SelectedDirectoryChanged event.

This example sets the Parent property for the DocumentList control to the form, making it occupy the entire client area of the form. If you want it to occupy a smaller area, you can place it in a Panel and specify the length. The width of a DocumentList should be the width of the form.

Visual Basic
 ' Set up file extension filters for a ' DocumentList and set the initial folder ' to the Busines folder under My Documents. Sub SetupDocList()     ' Assumes an instance of DocumentList,     ' d0cumentList1, has been declared.     With DocumentList1         .Parent = Me         .Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| " & _             "|*.pxl;*.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;"         .FilterIndex = 0         .SelectedDirectory = "Business"     End With End Sub' Handle the DocumentedActivated' event with code to open the file. Private Sub DocList_DocumentActivated(ByVal sender As Object, _     ByVal docevent As Microsoft.WindowsCE.Forms.DocumentListEventArgs) _     Handles DocumentList1.DocumentActivated     StatusBar1.Text = "Activated: " & docevent.Path ' Add code to open the selected file. End Sub ' Handle the DeletingDocument  ' event with code to close the file. Private Sub DocList_DeletingDocument(ByVal sender As Object, _     ByVal docevent As Microsoft.WindowsCE.Forms.DocumentListEventArgs) _     Handles DocumentList1.DeletingDocument     StatusBar1.Text = "Deleted: " & docevent.Path     ' Add code to close any instances of the file. End Sub ' Handle the SelectedDirectoryChanged ' event with code that sets the correct ' path for opening and closing files. Private Sub DocList_SelectedDirectoryChanged( _     ByVal sender As Object,  ByVal e As System.EventArgs) _     Handles DocumentList1.SelectedDirectoryChanged     StatusBar1.Text = "Folder: " & DocumentList1.SelectedDirectory     ' Add code to access the selected folder to open and close files.     End Sub
// Set up file extension filters for a// DocumentList and set the initial folder// to the Busines folder under My Documents. private void SetupDocList() {     // Assumes an instance of DocumentList,     // d0cumentList1, has been declared.     d0cumentList1.Parent = this;     // Create event handlers for DocumentList events.     d0cumentList1.DocumentActivated +=         new DocumentListEventHandler(this.OnDocActivated);     d0cumentList1.SelectedDirectoryChanged +=         new EventHandler(this.OnFolderSel);     d0cumentList1.DeletingDocument +=         new DocumentListEventHandler(this.OnDelDoc);     d0cumentList1.Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| " +         "|*.pxl;*.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;";     d0cumentList1.FilterIndex = 0;     d0cumentList1.SelectedDirectory = "Business"; } private void OnDelDoc(object obj, DocumentListEventArgs DocArgs) {     statusBar1.Text += "Deleted: " + DocArgs.Path;     // Add code to close any instances of the file. } private void OnDocActivated(object obj, DocumentListEventArgs DocArgs) {     statusBar1.Text = "Activated: " + DocArgs.Path;     // Add code to open the selected file. } private void OnFolderSel(object obj, EventArgs eventg) {     statusBar1.Text = "Folder: " + d0cumentList1.SelectedDirectory;     // Add code to access the selected folder to open and close files. }

This example requires references to the following namespaces:

LIST

'스마트 장치 개발' 카테고리의 다른 글

.NET Compact Framework How-to Topics  (1) 2009.12.16
file dialog for C#  (0) 2009.12.16
영어단어 암기 프로그램  (11) 2009.07.07
C#에서 aygshell.dll 사용 방법  (0) 2009.06.29
C#으로 fmodex.dll을 사용하는 예제  (0) 2009.06.29