Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Specified cast is not valid

Specified cast is not valid

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zulfikar Ali
    wrote on last edited by
    #1

    I am working on an application where user needs to select a folder. I am using dirListBox and DriveListBox from VB6. Reference's are Microsoft.Visualbasic.Compatibality and Microsoft.VisualBasic. It's populates the combo box for DriveListBox, but when i try to scroll down to select a drive , application bombs on me giving error An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.compatibility.dll "Specified Cast is not Valid" Any idea why it is doing that? Here is the code: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblStatus.Text = "Not Running" FindAllDrives() DriveListBox.SelectedIndex = 1 End Sub Private Sub FindAllDrives() Dim strDrives() As String strDrives = Directory.GetLogicalDrives Dim strDrive As String For Each strDrive In strDrives DriveListBox.Items.Add(strDrive) Next DriveListBox.SelectedIndex = 1 End Sub Private Sub DriveListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox.SelectedIndexChanged ' Dim folders() As String Try DirListBox.Path = DriveListBox.Text Catch MsgBox("Can't access selected drive") End Try End Sub Private Sub DirListBox_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox.SelectedIndexChanged lblFolder.Text = DirListBox.Path.ToString strFolder = lblFolder.Text End Sub Please help if you have any idea! Thank you. Zulfikar Ali

    Z 1 Reply Last reply
    0
    • Z Zulfikar Ali

      I am working on an application where user needs to select a folder. I am using dirListBox and DriveListBox from VB6. Reference's are Microsoft.Visualbasic.Compatibality and Microsoft.VisualBasic. It's populates the combo box for DriveListBox, but when i try to scroll down to select a drive , application bombs on me giving error An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.compatibility.dll "Specified Cast is not Valid" Any idea why it is doing that? Here is the code: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblStatus.Text = "Not Running" FindAllDrives() DriveListBox.SelectedIndex = 1 End Sub Private Sub FindAllDrives() Dim strDrives() As String strDrives = Directory.GetLogicalDrives Dim strDrive As String For Each strDrive In strDrives DriveListBox.Items.Add(strDrive) Next DriveListBox.SelectedIndex = 1 End Sub Private Sub DriveListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox.SelectedIndexChanged ' Dim folders() As String Try DirListBox.Path = DriveListBox.Text Catch MsgBox("Can't access selected drive") End Try End Sub Private Sub DirListBox_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox.SelectedIndexChanged lblFolder.Text = DirListBox.Path.ToString strFolder = lblFolder.Text End Sub Please help if you have any idea! Thank you. Zulfikar Ali

      Z Offline
      Z Offline
      Zulfikar Ali
      wrote on last edited by
      #2

      I figure out the problem. I am using DriveListBox and in the same time using a function to populate the DriveListBox combobox. I eliminated the FinDAllDrives and woolaaa. Thanks.;) Zulfikar Ali

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups