Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

SimpleExplorer Sample (C#)

This sample illustrates implementation of a simple Windows Explorer/File Explorer.

The source code is located at C:\Program Files (x86)\Softelvdm\SftDirectory 3.5\Samples\Visual Studio - CSharp\SimpleExplorer\Form1.cs or C:\Program Files\Softelvdm\SftDirectory 3.5\Samples\Visual Studio - CSharp\SimpleExplorer\Form1.cs (on 32-bit Windows versions).

private void Form1_Load(object sender, System.EventArgs e) {
    UpdateLeftButtons();
    UpdateRightButtons();
    axSftDirectoryRight.MakeColumnsOptimal();
}

private void UpdateLeftButtons()
{
    // Update the buttons dependent on the left tree
    SftDirectoryFolder f;
    // Enable/disable Up button
    f = axSftDirectoryLeft.CurrentFolder;
    if (f != null)
        f = f.Parent;
    buttonUp.Enabled = (f != null);
}

private void UpdateRightButtons()
{
    // Update the buttons dependent on the right side detaillist
    SftDirectoryFolder f;
    // Enable/disable properties button
    f = axSftDirectoryRight.CurrentFolder;
    buttonProp.Enabled = false;
    if (axSftDirectoryRight.SelectionCount > 0 && f != null) {
        if (f.Can("properties"))
            buttonProp.Enabled = true;
    }

    // Enable/disable New Folder button
    f = axSftDirectoryRight.RootFolder;
    buttonNewFolder.Enabled = false;
    if (f != null) {
        if (f.Can("NewFolder"))
            buttonNewFolder.Enabled = true;
    }
}

private void axSftDirectoryLeft_SelectionFinal(object sender, System.EventArgs e) {
    // If the selection in the left tree changes, update right side detaillist
    UpdateLeftButtons();
    axSftDirectoryRight.Clear();
    axSftDirectoryRight.CancelMode();
    axSftDirectoryRight.Refresh();
    if (axSftDirectoryLeft.CurrentFolder != null)
        axSftDirectoryRight.TopMostFolderIDL = axSftDirectoryLeft.CurrentFolder.ItemIDList;
    else
        axSftDirectoryRight.TopMostFolderSpecial = SftDirectorySpecialFolderConstants.specialSftDirectoryEmpty;
}

private void axSftDirectoryRight_Opening(object sender, AxSftDirectoryLib30._ISftDirectoryEvents_OpeningEvent e) {
    SftDirectoryFolder f;
    String IDL;
    // we're about to open a file/folder.  If we can add the folder on the
    // left side, that means we don't need to open it in a separate window

    IDL = e.folder.ItemIDList; // the folder we are looking for
    // this will add the complete hierarchy down to the folder in
    // left tree (if possible)
    f = axSftDirectoryLeft.get_FolderUsingIDL(IDL, false);
    // this will locate the exact item if we just added it
    f = axSftDirectoryLeft.get_FolderUsingIDL(IDL, true);
    if (f != null) {
        // The folder has been added on the left side
        f.MakeCurrent(); // make it the current item
        f.MakeVisible(); // make sure it's scrolled into view
        e.allow = false; // no need to open it
    }
}

private void axSftDirectoryRight_SelectionFinal(object sender, System.EventArgs e) {
    UpdateRightButtons();
    if (axSftDirectoryRight.CurrentFolder != null)
        statusBar.Text = axSftDirectoryRight.CurrentFolder.InfoTip;
    else
        statusBar.Text = "";
}

private void buttonUp_Click(object sender, System.EventArgs e) {
    // Move up on level in left side tree control
    SftDirectoryFolder f;
    f = axSftDirectoryLeft.CurrentFolder;
    if (f != null) {
        f = f.Parent;
        if (f != null) {
            f.MakeCurrent(); // make it the current item
            f.MakeVisible(); // make sure it's scrolled into view
        }
    }
}

private void buttonProp_Click(object sender, System.EventArgs e) {
    // Display properties dialog for the currently selected item
    SftDirectoryFolder f;
    f = axSftDirectoryRight.CurrentFolder;
    if (axSftDirectoryRight.SelectionCount > 0 && f != null)
        f.Do("properties");
}

private void buttonNewFolder_Click(object sender, System.EventArgs e) {
    // Create a new folder
    SftDirectoryFolder f;
    f = axSftDirectoryRight.RootFolder;
    if (f != null) {
        try {
            f.Do("NewFolder");
        } catch  
    }
}

private void axSftDirectoryLeft_KeyDownEvent(object sender, AxSftDirectoryLib30._ISftDirectoryEvents_KeyDownEvent e) {
    // F5 automatically reloads left side, but we also want right side updated
    if (e.keyCode == (short) Keys.F5) axSftDirectoryRight.Reload(true, true);
}

private void axSftDirectoryRight_KeyDownEvent(object sender, AxSftDirectoryLib30._ISftDirectoryEvents_KeyDownEvent e) {
    // F5 automatically reloads right side, but we also want left side updated
    if (e.keyCode == (short) Keys.F5) axSftDirectoryLeft.Reload(true, true);
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.