School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 353,811 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,422 people online right now.Registration is fast and FREE... Join Now!



how to get drives in a combo box along with their names

52 Weeks of Code Challenge: WPF

Week #10 of the 52 Weeks of Code Challenge is WPF. If you're a .NET programmer, you should give it a shot. Click Here!
Page 1 of 1

how to get drives in a combo box along with their names Rate Topic: -----

#1 umeshshivakanth  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-April 08


Dream Kudos: 0

Posted 24 April 2008 - 11:13 PM

how to get drives in a combo box along with their names and drive image??
Plz help me....If u do have an answer plz mail me the code to umeshshivakanth@gmail.com


Thanks
Was This Post Helpful? 0
  • +
  • -


#2 Jayman  Icon User is offline

  • Student of Life
  • Icon

Reputation: 295
  • View blog
  • Posts: 8,984
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Re: how to get drives in a combo box along with their names

Posted 25 April 2008 - 07:23 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 umeshshivakanth  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-April 08


Dream Kudos: 0

Re: how to get drives in a combo box along with their names

Posted 25 April 2008 - 09:26 PM

Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sDrive As String, sDrives() As String
sDrives = ListAllDrives()
For Each sDrive In sDrives
Debug.WriteLine(sDrive)
Next

Me.ComboBox1.Items.AddRange(ListAllDrives())
End Sub

Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = Directory.GetLogicalDrives()
Return arDrives
End Function



This code gets me only drive letters but i want them in this format with drive image:FORMAT: (drive image) localdisk driveletter

EDIT: Code blocks added => :code:

This post has been edited by PsychoCoder: 25 April 2008 - 09:41 PM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon

Reputation: 701
  • View blog
  • Posts: 16,787
  • Joined: 26-July 07


Dream Kudos: 12450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: how to get drives in a combo box along with their names

Posted 25 April 2008 - 09:50 PM

You're going to want to use the DriveInfo Class, this class will allow you to get lots of information about the drives on the system. You can use Name to get the name of the drive, and VolumeLable to get the drives label (the name that is displayed). Here's an example


Public Function ListAllDrives() As String()
      'Use DriveInfo to gain access to the drives properties
      Dim allDrives() As DriveInfo = DriveInfo.GetLogicalDrives()

      'loop through all the drives on the system
      For Each d In allDrives
            'Add each drive to my ComboBox, in the format
            ' C: - MyDrive
            ComboBox1.Items.Add(d.Name + " - " + d.VolumeLabel)
      Next 
End Function


Was This Post Helpful? 0
  • +
  • -

#5 umeshshivakanth  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-April 08


Dream Kudos: 0

Re: how to get drives in a combo box along with their names

Posted 25 April 2008 - 10:01 PM

thanks for the suggestion but there's an error at this line of code
Dim allDrives() As DriveInfo = DriveInfo.GetLogicalDrives()
i think i need to import some namespace .....please do tell me that.....


thanks
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon

Reputation: 701
  • View blog
  • Posts: 16,787
  • Joined: 26-July 07


Dream Kudos: 12450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: how to get drives in a combo box along with their names

Posted 25 April 2008 - 10:03 PM

Dim allDrives() As DriveInfo = DriveInfo.GetDrives()



Sorry about that, I was looking at your code and typing at the same time lol

This post has been edited by PsychoCoder: 25 April 2008 - 10:05 PM

Was This Post Helpful? 0
  • +
  • -

#7 umeshshivakanth  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-April 08


Dream Kudos: 0

Re: how to get drives in a combo box along with their names

Posted 26 April 2008 - 01:34 AM

again there's a small problem ........the compiler is saying
"d is not declared"

if thats not a problem ......I am not still getting drive name(local disk) and label
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon

Reputation: 701
  • View blog
  • Posts: 16,787
  • Joined: 26-July 07


Dream Kudos: 12450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: how to get drives in a combo box along with their names

Posted 26 April 2008 - 04:40 AM

For Each d As DriveInfo In allDrives


Next




You're going to have to figure out things on your own as well, you cannot always rely on someone doing your work for you. When it says something is not declared, then declare it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month