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. vb.net 2010 desktop app value displayed in combo box

vb.net 2010 desktop app value displayed in combo box

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
3 Posts 3 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.
  • C Offline
    C Offline
    classy_dog
    wrote on last edited by
    #1

    In a Visual basic.net 2010 desktop application, I am loading a list of Access 2013 files that the user needs to select to work with. The code listed below is correct but the file names are too long for the combo box. Here is the code:

    Try

    Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")

    Dim dir As String

    For Each dir In dirAccessFiles

    cboAccessFile.Items.Add(dir)

    Next

    Catch except As Exception

    Console.WriteLine("The process failed: {0}", e.ToString())

    End Try

    Thus I have the following questions to ask you: 1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that? 2. Right now in dropdownlist box, the values look like, 'H:\Testfiles\Diane__Currentyear.accdb'. I would like the value only of 'Diane__Currentyear' that is listed above to display. Also where hardcoded value of 'H:\Testfiles' is displayed in the code above, I will get the actual value from the app. config file. Thus would you show the code on how to display only the value of 'Diane__Currentyear' in the list of combo box values?

    S 1 Reply Last reply
    0
    • C classy_dog

      In a Visual basic.net 2010 desktop application, I am loading a list of Access 2013 files that the user needs to select to work with. The code listed below is correct but the file names are too long for the combo box. Here is the code:

      Try

      Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")

      Dim dir As String

      For Each dir In dirAccessFiles

      cboAccessFile.Items.Add(dir)

      Next

      Catch except As Exception

      Console.WriteLine("The process failed: {0}", e.ToString())

      End Try

      Thus I have the following questions to ask you: 1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that? 2. Right now in dropdownlist box, the values look like, 'H:\Testfiles\Diane__Currentyear.accdb'. I would like the value only of 'Diane__Currentyear' that is listed above to display. Also where hardcoded value of 'H:\Testfiles' is displayed in the code above, I will get the actual value from the app. config file. Thus would you show the code on how to display only the value of 'Diane__Currentyear' in the list of combo box values?

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #2

      classy_dog wrote:

      1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that?

      I suggest an alternative, which is more elegant IMO. This article: Adjust combo box drop down list width to longest string width[^] and maybe additionally dock the ComboBox horizontally in its container so that the user can adjust its width by expanding the window horizontally (see the Dock-property of the ComboBox-control in the designer).

      classy_dog wrote:

      I would like the value only of 'Diane__Currentyear' that is listed above to display.

      Path.GetFileNameWithoutExtension[^] does the trick.

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      R 1 Reply Last reply
      0
      • S Sascha Lefevre

        classy_dog wrote:

        1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that?

        I suggest an alternative, which is more elegant IMO. This article: Adjust combo box drop down list width to longest string width[^] and maybe additionally dock the ComboBox horizontally in its container so that the user can adjust its width by expanding the window horizontally (see the Dock-property of the ComboBox-control in the designer).

        classy_dog wrote:

        I would like the value only of 'Diane__Currentyear' that is listed above to display.

        Path.GetFileNameWithoutExtension[^] does the trick.

        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

        R Offline
        R Offline
        Ralf Meier
        wrote on last edited by
        #3

        ... and if you don't want that the path is displayed in the Combobox you can write :

        cboAccessFile.Items.Add(dir.replace("H:\FilesTest\",""))

        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