Monday, September 12, 2011

Myth self note 5: c# WPF - FolderBrowserDialog and listBox

My note on how to open and add folder path to listbox in WPF C#.


1) Right click -> Add Reference (Right click either on the project name "WPF1" or "Reference")
2) .NET -> System.Windows.Forms -> OK


3) using System.Windows.Forms
4) private FolderBrowserDialog openFolder = new FolderBrowserDialog();


5) btnAdd
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog browseFolder = new FolderBrowserDialog();
openFolder.SelectedPath = "C:\\";
DialogResult result = openFolder.ShowDialog();
if (result.ToString() == "OK")
{
lstPath.Items.Add(openFolder.SelectedPath);
}
}
6) btnRemove
private void btnRmv_Click(object sender, RoutedEventArgs e)
{
lstPath.Items.RemoveAt(lstPath.Items.IndexOf(lstPath.SelectedItem));
}


Example Run

themythstoodstill: note for myth future self, picture/figure explain itself..13/sep/2011

5 comments:

Home said...

Hello, it was so helpful for me.

Home said...

Hello, it was so helpful for me.

Home said...

Hello, it was so helpful for me.

matnormyth89 said...

Thanks for the feedback..
glad that my note can help others..

tuan nguyenngoc said...

I think you could use:
System.Windows.Forms.FolderBrowserDialog Browser = new System.Windows.Forms.FolderBrowserDialog();
instead
FolderBrowserDialog Browser = new FolderBrowserDialog();