ListBox not showing items

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • koosh34

    ListBox not showing items

    VS2005 VB.net 2.0
    I have a form called options with a ListBox1 on it, to fill the list box
    from several events on the form I put the code to update the ListBox1 items
    into a sub in a separate code module.

    Private Sub options_Load(By Val sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    updateOptionsLi stView()
    End Sub

    And in the seperate code module

    Public Sub updateOptionsLi stView()
    Dim form As New options()
    form.ListBox1.I tems.Add(System .IO.Path.GetFil eNameWithoutExt ension("test"))
    End Sub

    If the line
    "Me.ListBox1.It ems.Add(System. IO.Path.GetFile NameWithoutExte nsion("test"))"
    is placed in the options_load sub it works but when I call it from the
    separate code module it does not. I think this is because another instance
    of the options form is being updated.
    I also tried

    Public Sub updateOptionsLi stView()
    options.ListBox 1.Items.Add(Sys tem.IO.Path.Get FileNameWithout Extension("test "))
    End Sub

    But I get a warning "Reference to a non-shared member requires an object
    reference" and the ListBox does not update either.
    How do I get around this problem?


  • Huy Thai

    #2
    Re: ListBox not showing items

    You may try this -

    Dim frm As options
    Dim fn As Form

    For Each fn In My.Application. OpenForms
    If TypeOf fn Is options Then
    frm = DirectCast(fn, options)
    frm.ListBox1.It ems.Add(System. IO.Path.GetFile NameWithoutExte nsion("test"))
    frm = Nothing
    End If
    Next
    fn = Nothing

    "koosh34" <koosh34@hotmai l.comwrote in message
    news:ur2VUjxlIH A.1208@TK2MSFTN GP03.phx.gbl...
    VS2005 VB.net 2.0
    I have a form called options with a ListBox1 on it, to fill the list box
    from several events on the form I put the code to update the ListBox1
    items into a sub in a separate code module.
    >
    Private Sub options_Load(By Val sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    updateOptionsLi stView()
    End Sub
    >
    And in the seperate code module
    >
    Public Sub updateOptionsLi stView()
    Dim form As New options()
    form.ListBox1.I tems.Add(System .IO.Path.GetFil eNameWithoutExt ension("test"))
    End Sub
    >
    If the line
    "Me.ListBox1.It ems.Add(System. IO.Path.GetFile NameWithoutExte nsion("test"))"
    is placed in the options_load sub it works but when I call it from the
    separate code module it does not. I think this is because another instance
    of the options form is being updated.
    I also tried
    >
    Public Sub updateOptionsLi stView()
    options.ListBox 1.Items.Add(Sys tem.IO.Path.Get FileNameWithout Extension("test "))
    End Sub
    >
    But I get a warning "Reference to a non-shared member requires an object
    reference" and the ListBox does not update either.
    How do I get around this problem?
    >

    Comment

    • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

      #3
      RE: ListBox not showing items

      koosh34,

      One option would be to put the sub that updates the listbox in the form's
      code, not a separate module.

      Another option would be to send the listbox to be updated to the
      subprocedure as an argument:

      Public Sub updateOptionsLi stView(ByVal lb as ListBox)

      lb.Items.Add(Sy stem.IO.Path.Ge tFileNameWithou tExtension("tes t"))

      End Sub

      Kerry Moorman

      "koosh34" wrote:
      VS2005 VB.net 2.0
      I have a form called options with a ListBox1 on it, to fill the list box
      from several events on the form I put the code to update the ListBox1 items
      into a sub in a separate code module.
      >
      Private Sub options_Load(By Val sender As Object, ByVal e As
      System.EventArg s) Handles Me.Load
      updateOptionsLi stView()
      End Sub
      >
      And in the seperate code module
      >
      Public Sub updateOptionsLi stView()
      Dim form As New options()
      form.ListBox1.I tems.Add(System .IO.Path.GetFil eNameWithoutExt ension("test"))
      End Sub
      >
      If the line
      "Me.ListBox1.It ems.Add(System. IO.Path.GetFile NameWithoutExte nsion("test"))"
      is placed in the options_load sub it works but when I call it from the
      separate code module it does not. I think this is because another instance
      of the options form is being updated.
      I also tried
      >
      Public Sub updateOptionsLi stView()
      options.ListBox 1.Items.Add(Sys tem.IO.Path.Get FileNameWithout Extension("test "))
      End Sub
      >
      But I get a warning "Reference to a non-shared member requires an object
      reference" and the ListBox does not update either.
      How do I get around this problem?
      >
      >
      >

      Comment

      Working...