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
J

Jens Madsen Hojby

@Jens Madsen Hojby
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • vb.net combo box
    J Jens Madsen Hojby

    Private Function reverseFileNameComparer() As Comparison(Of String)
    Return Function(x, y) (String.Compare(Path.GetFileNameWithoutExtension(y), Path.GetFileNameWithoutExtension(x), StringComparison.OrdinalIgnoreCase))
    End Function

    Private Sub AddToCombo(combo As ComboBox, directoryPath As String, filter As String)
    ' Error check, 'IsNothing(combo)' and 'IO.Directory.Exists(directoryPath)' bla-bla
    combo.BeginUpdate()
    For Each fn As String In Directory.EnumerateFiles(directoryPath).OrderByDescending(Function(f) (Path.GetFileNameWithoutExtension(f)))
    combo.Items.Add(Path.GetFileNameWithoutExtension(fn))
    Next
    combo.EndUpdate()

      ' Or...
      Dim files() As String = Directory.GetFiles(directoryPath, filter)
      Array.Sort(files, reverseFileNameComparer)
      combo.Items.AddRange(Array.ConvertAll(files, AddressOf Path.GetFileNameWithoutExtension))
    
      'Since you want to order by file name, I suggest you use the System.IO namespace:
      'You could:
      combo.FormattingEnabled = True
      'Add a handler to 'ComboBox.Format -
      'or --
      combo.DisplayMember = "Name"
      combo.BeginUpdate()
      For Each fio As FileInfo In New DirectoryInfo(directoryPath).EnumerateFiles(filter).OrderByDescending(Function(f) (f.Name))
          combo.Items.Add(fio.Name)
    
      Next
      combo.EndUpdate()
    

    End Sub

    Private Sub cboFileInfo_format(sender As Object, e As ListControlConvertEventArgs)
    Dim f As FileInfo = DirectCast(e.ListItem, FileInfo)
    e.Value = f.Name.Substring(f.Name.LastIndexOf("."c) + 1)
    End Sub

    Visual Basic csharp tutorial question
  • Login

  • Don't have an account? Register

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