Results 1 to 2 of 2

Thread: FolderBrowserDialog?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    20

    FolderBrowserDialog?

    Hey I am trying to create an folder browser that will allow you to select the folders and files and "open" them so the path get saved into a richtextbox.

    this is my code.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    
    
    namespace Windows_Tools
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private Hashtable extendees;
    
            private void btn_backup_Click_1(object sender, EventArgs e)
            {
                FolderBrowserDialog f_browser = new FolderBrowserDialog();
                DialogResult result = f_browser.ShowDialog();
                Control btn = sender as Control;
                extendees = new Hashtable();
                if (result == DialogResult.OK)
                {
                    foreach (DictionaryEntry ent in extendees)
                    {
                        if (ent.Value == btn)
                        {
                            Control target = ent.Key as Control;
                            test.Text = f_browser.SelectedPath;
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Operation was aborted", "Error:");
                }
            }
        }
    }
    the open thingy works


    I need your help to get it to copy the path into my richtextbox.

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: FolderBrowserDialog?

    Quote Originally Posted by Daemoncraft
    Hey I am trying to create an folder browser that will allow you to select the folders and files and "open" them so the path get saved into a richtextbox.

    this is my code.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    
    
    namespace Windows_Tools
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private Hashtable extendees;
    
            private void btn_backup_Click_1(object sender, EventArgs e)
            {
                FolderBrowserDialog f_browser = new FolderBrowserDialog();
                DialogResult result = f_browser.ShowDialog();
                Control btn = sender as Control;
                extendees = new Hashtable();
                if (result == DialogResult.OK)
                {
                    foreach (DictionaryEntry ent in extendees)
                    {
                        if (ent.Value == btn)
                        {
                            Control target = ent.Key as Control;
                            test.Text = f_browser.SelectedPath;
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Operation was aborted", "Error:");
                }
            }
        }
    }
    the open thingy works


    I need your help to get it to copy the path into my richtextbox.
    Your code is badly designed. Rethink what you want to do before you try to code it.

    You initialize extendees as a HashTable with new() and then try to enumerate through the entries in the HashTable but it doesn't have anything in it. You never enter the foreach() loop since the HashTable has no entries. In that case you will never get to the statement that sets your text to the selected path.

    Why are you trying to use a HashTable?

    It looks like maybe you're trying to see if the button clicked is an entry in the hash table. For what reason I don't know. Is this your complete code?

    You declare Control target and never use it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width