How to: Use a DocumentList Control

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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.

Example

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.

 ' 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,
     ' documentList1, 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,
     // documentList1, has been declared.
     documentList1.Parent = this;

     // Create event handlers for DocumentList events.
     documentList1.DocumentActivated +=
         new DocumentListEventHandler(this.OnDocActivated);

     documentList1.SelectedDirectoryChanged +=
         new EventHandler(this.OnFolderSel);

     documentList1.DeletingDocument +=
         new DocumentListEventHandler(this.OnDelDoc);

     documentList1.Filter = " |*.*| |*.txt;*.xml| |*.pwi;*.pdt| " +
         "|*.pxl;*.psw| |*.jpg;*.gif;*.bmp| |*.wav;*.wmv;*.mpg;";
     documentList1.FilterIndex = 0;
     documentList1.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: " + documentList1.SelectedDirectory;

     // Add code to access the selected folder to open and close files.
 }

Compiling the Code

This example requires references to the following namespaces:

See Also

Reference

DocumentList

Other Resources

Pocket PC Development and the .NET Compact Framework