1 Replies - 5478 Views - Last Post: 05 August 2008 - 11:31 AM Rate Topic: -----

#1 jee  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 20-April 08

POPULATING SUBDIRECTORIES IN LISTBOX

Posted 26 April 2008 - 06:42 PM

Hi Frnds!!!!
pls help me i m in need of a code...

first i want to describe my need...
in C#(WPF) i want a combobox and a listbox in which i need all logical drives to be populated in tha combobox and its directory should be populated in the listbox when a drive is selected..
here i wrote the code for populating drives in combobox and i got the output and the code is given below but i cant get the code for getting its subdirectory in listbox...
private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			try
			{
				foreach (string logicalDrive in Environment.GetLogicalDrives())
				{
					comboBox1.Items.Add(logicalDrive);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}



i have done this same application in VB.NET and got the output.
the vb coding for populating the subdirectories in listbox is as follows.
Public Sub AddDirectory(ByVal subdir1 As String)
		For Each subdir As String In System.IO.Directory.GetDirectories(subdir1)
			'add the directory to the Listbox
			Me.ListBox1.Items.Add(subdir)

			Try
				'check if there are more sub directories
				If System.IO.Directory.GetDirectories(subdir).Length <> 0 Then
					AddDirectory(subdir)
				End If
			Catch ex As Exception

			End Try
		Next
	End Sub


i cant find a way to convert it to C# coding..(for populating the sub directories in listbox)
Pls frnds help me out to overcome my problem and give a favourable reply..
thanks in advance....

This post has been edited by jee: 27 April 2008 - 01:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: POPULATING SUBDIRECTORIES IN LISTBOX

#2 gbeltrao  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-July 08

Re: POPULATING SUBDIRECTORIES IN LISTBOX

Posted 05 August 2008 - 11:31 AM

View Postjee, on 26 Apr, 2008 - 06:42 PM, said:

Hi Frnds!!!!
pls help me i m in need of a code...

first i want to describe my need...
in C#(WPF) i want a combobox and a listbox in which i need all logical drives to be populated in tha combobox and its directory should be populated in the listbox when a drive is selected..
here i wrote the code for populating drives in combobox and i got the output and the code is given below but i cant get the code for getting its subdirectory in listbox...
private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			try
			{
				foreach (string logicalDrive in Environment.GetLogicalDrives())
				{
					comboBox1.Items.Add(logicalDrive);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}



i have done this same application in VB.NET and got the output.
the vb coding for populating the subdirectories in listbox is as follows.
Public Sub AddDirectory(ByVal subdir1 As String)
		For Each subdir As String In System.IO.Directory.GetDirectories(subdir1)
			'add the directory to the Listbox
			Me.ListBox1.Items.Add(subdir)

			Try
				'check if there are more sub directories
				If System.IO.Directory.GetDirectories(subdir).Length <> 0 Then
					AddDirectory(subdir)
				End If
			Catch ex As Exception

			End Try
		Next
	End Sub


i cant find a way to convert it to C# coding..(for populating the sub directories in listbox)
Pls frnds help me out to overcome my problem and give a favourable reply..
thanks in advance....

Hello Jee,
Here's the code translated:
 public void AddDirectory(string subdir1)
 {
	 foreach (string subdir in System.IO.Directory.GetDirectories(subdir1)) {
		 //add the directory to the Listbox
		 this.ListBox1.Items.Add(subdir);
		
		 try {
			 //check if there are more sub directories
			 if (System.IO.Directory.GetDirectories(subdir).Length != 0) {
				 AddDirectory(subdir);
			 }
		 }
		 catch (Exception ex) {
			
		 }
	 }
 }



And here's a free tool to translate your VB.NET code to C#:

VB.NET to C#

Regards,
Gilberto

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1