how to get drives in a combo box along with their names
Page 1 of 1
how to get drives in a combo box along with their names
#2
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:
Thanks.
Post your code like this:
Thanks.
#3
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 =>
This post has been edited by PsychoCoder: 25 April 2008 - 09:41 PM
#4
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
#5
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
Dim allDrives() As DriveInfo = DriveInfo.GetLogicalDrives()
i think i need to import some namespace .....please do tell me that.....
thanks
#8
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
Page 1 of 1

Add Reply





MultiQuote

| 


