0

I am developing an Bootstrapper application. When we move to the installation location selection wizard, we can have a browse option to change the location of our setup installation.

When we clock that browse option, i need to show only the drives( 'C', 'D' and 'F') available in a system. When we select the drive, it will not expand. i need that drive alone (Ex: C:) in the installation location text in the installation wizard.

Can anyone please guide me that how to achieve my requirement?

My code:

private void btn_Browse_Click(object sender, EventArgs e)
{
  txt_InstallLocation.Focus();
  FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;

  if (FBD_Source.ShowDialog() == DialogResult.OK)
  {
    txt_InstallLocation.TextBox.Text = FBD_Source.SelectedPath;
    BA.Model.Bootstrapper.Engine.StringVariables["APPDIR"] = FBD_Source.SelectedPath + "\\";
  }
}

I need to modify the below line of code.

FBD_Source.RootFolder = Environment.SpecialFolder.Desktop;

Can anyone please assist me to proceed further or direct me in right path?

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Karthi
  • 575
  • 2
  • 10
  • 29

1 Answers1

0

Your can find the available drives like this.

var drives = System.Environment.GetLogicalDrives();
foreach (string d in drives)
       Console.WriteLine(d);

Don't use the FolderBrowserDialog.
Create a form with a dynamically created radiobutton/list and make the user select one of those options

Something like this

        var drives = System.Environment.GetLogicalDrives();

        Form selectionForm = new Form() { MaximizeBox = false, FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog, StartPosition = FormStartPosition.CenterScreen };


        ListBox lb = new ListBox() { Dock = DockStyle.Fill };
        foreach (var item in drives)
            lb.Items.Add(item);
        selectionForm.Controls.Add(lb);

        Button btnOk = new Button() { Dock = DockStyle.Left, Width = selectionForm.Width / 2 };
        btnOk.Text = "OK";
        Button btnCancel = new Button() { Dock = DockStyle.Right, Width = selectionForm.Width / 2 };
        btnCancel.Text = "Cancel";


        Panel bottomPanel = new Panel() { Dock = DockStyle.Bottom, Height = 50 };

        bottomPanel.Controls.Add(btnOk);
        bottomPanel.Controls.Add(btnCancel);
        selectionForm.Controls.Add(bottomPanel);
        selectionForm.ShowDialog();
        MessageBox.Show(lb.SelectedItem.ToString());
George Vovos
  • 7,563
  • 2
  • 22
  • 45
  • Can i use Treegrid instead of listbox. And also can i display the driver image before each drive letter? – Karthi Aug 21 '14 at 13:11
  • Can you please suggest me some links which will be useful to learn more about WindowsForms? Since all these things i want do in Windows Forms. – Karthi Aug 21 '14 at 13:12
  • http://stackoverflow.com/questions/6361376/good-books-for-windows-forms-and-gdi Why use a tree when you only have a list of drives? – George Vovos Aug 21 '14 at 13:49
  • My requirement is to create a Form as like folder browser dialog. So i thought to use treegrid. Due to "Dock = DockStyle.Fill", list box was set to full form. But it should not be like that in my requirement(as per the folder browser dialog). since i need to have 2 buttons under the listbox in the form. can you please help. – Karthi Aug 21 '14 at 17:15
  • Check my updated answer. You can create the form using the visual studio designer if it is easier for you. I don't think i can help you any more – George Vovos Aug 21 '14 at 17:30