Very Unpredictable ListBox Behaviour

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

    #1

    Very Unpredictable ListBox Behaviour

    This is driving me NUTS. I have a listbox bound to a datasource and it
    all works fine until I start deleting items from the class collection.
    The frustrating thing is that there is no pattern to the error and I
    can't recreate the problem with any certainty. I refresh the listbox
    after deleting a class item with the following code:

    With lstBanks
    .DataSource = Nothing
    .DisplayMember = "Title"
    .ValueMember = "BankID"
    .DataSource = Banks
    End With

    Generally everything works fine - after a class item is deleted the
    listbox displays the correct items using the refresh code above.
    HOWEVER every now and again the listbox starts to fill itself with the
    class name, i.e. repeated lines of 'MyProgram.Bank ' (the number of
    lines is always equivalent to the correct number of items that should
    be displayed in the listbox). Then the program will crash when a
    listbox item is clicked. It seems obvious to me that the DisplayMember
    and ValueMember are not being properly set (or ignored) for some reason
    (I have checked these values after the problem appears and they seem to
    be set fine).

    I have tried just about every combination of lines including refresh,
    different order of lines etc. etc..

    Any help would be very much appreciated.

    Alan

  • Cor Ligthert [MVP]

    #2
    Re: Very Unpredictable ListBox Behaviour

    Alanb,

    Are you sure that this is not happen when you delete a selected item.
    Than there is a selectedindex change event and that will be triggered.

    I hope this helps,

    Cor

    "alanb" <abilsborough@g mail.com> schreef in bericht
    news:1141425967 .858678.219340@ v46g2000cwv.goo glegroups.com.. .[color=blue]
    > This is driving me NUTS. I have a listbox bound to a datasource and it
    > all works fine until I start deleting items from the class collection.
    > The frustrating thing is that there is no pattern to the error and I
    > can't recreate the problem with any certainty. I refresh the listbox
    > after deleting a class item with the following code:
    >
    > With lstBanks
    > .DataSource = Nothing
    > .DisplayMember = "Title"
    > .ValueMember = "BankID"
    > .DataSource = Banks
    > End With
    >
    > Generally everything works fine - after a class item is deleted the
    > listbox displays the correct items using the refresh code above.
    > HOWEVER every now and again the listbox starts to fill itself with the
    > class name, i.e. repeated lines of 'MyProgram.Bank ' (the number of
    > lines is always equivalent to the correct number of items that should
    > be displayed in the listbox). Then the program will crash when a
    > listbox item is clicked. It seems obvious to me that the DisplayMember
    > and ValueMember are not being properly set (or ignored) for some reason
    > (I have checked these values after the problem appears and they seem to
    > be set fine).
    >
    > I have tried just about every combination of lines including refresh,
    > different order of lines etc. etc..
    >
    > Any help would be very much appreciated.
    >
    > Alan
    >[/color]


    Comment

    • alanb

      #3
      Re: Very Unpredictable ListBox Behaviour

      Many thanks for the reply Cor,

      I've added more protection to the events and yes it does seem to be
      much more stable - it's even more difficult to reproduce the problem
      now, BUT it still happens on rare occasions! When I create a new file
      the program seems to run very well, however the problem seems to happen
      only after I've stopped the program and run it again (although it still
      very rarely happens and not immediately after loading the previous
      data) .

      I save my data via serialization rather than dumping to a database -
      I'm beginning to wonder if this is causing a problem.

      Alan

      Comment

      Working...