Click here to Skip to main content
15,849,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Currently I am able to display icons and drive volume letter in my combobox. I would like to be able to also display the drive type or name along with the volume letter as follows:

(example) Icon LocalDrive C:\
Icon Second Drive D:\
Icon CDROM E:\
ect..............................

Thank you for your time!!
Posted
Comments
Sergey Alexandrovich Kryukov 9-Jul-11 23:29pm    
Tag it! WPF or Forms or what?!
--SA
Sergey Alexandrovich Kryukov 9-Jul-11 23:31pm    
Do not re-post. Use "Improve question" on you previous one.
--SA

This[^] will give you what you need.
 
Share this answer
 
 
Share this answer
 
Comments
Dale 2012 9-Jul-11 3:41am    
Ok I will submit the code I have so far in hopes someone will add the few lines of code that i am missing?

I know I am close to success but it has me stumped even with the links that I have visited

Public Class Form1
Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = Directory.GetLogicalDrives()
Return arDrives
End Function
Public Sub New()
Call InitializeComponent()
If LicenseManager.UsageMode <> LicenseUsageMode.Designtime Then
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
ComboBox1.Items.Add(drive_info.Name & " ")
ComboBox1.Items.Add(drive_info.RootDirectory.ToString)
If drive_info.IsReady() Then
ComboBox1.Items.Add(drive_info.VolumeLabel())
End If
Next drive_info
ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index = -1 Then
Return
End If
Dim drive As DriveInfo = CType(ComboBox1.Items(e.Index), DriveInfo)
Dim icon As Icon
Select Case drive.DriveType
Case (DriveType.Fixed)
icon = ShellIcons.HardDisk
Case (DriveType.CDRom)
icon = ShellIcons.CDROM
Case (DriveType.Network)
icon = ShellIcons.NetDisk
Case (DriveType.Removable)
icon = ShellIcons.FloppyDisk
Case Else
icon = ShellIcons.UnknownDisk
End Select
Dim iconbox As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
e.DrawBackground()
e.Graphics.DrawIcon(icon, iconbox)
icon.Dispose()
Dim text As String = drive.Name
If drive.IsReady Then
If drive.VolumeLabel <> "" Then
text = text & " (" & drive.VolumeLabel & ")"
End If
End If
e.Graphics.DrawString(text, e.Font, New SolidBrush(e.ForeColor), e.Bounds.X + iconbox.Width + 1, e.Bounds.Y)
If e.State = DrawItemState.Focus Then
e.DrawFocusRectangle()
End If
End Sub
End Class
Sergey Alexandrovich Kryukov 9-Jul-11 23:30pm    
OK, now I see: Forms. Tag is in your questions. This is in your interest, to get attention of people who can and will ask your question. Always do.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900