ListBox Items not Updating/Refreshing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gdbjohnson-AT-yahoo-dot-ca-nospamplz

    ListBox Items not Updating/Refreshing

    I have a ListBox built of a simple custom object for the
    ListItems used to be able to hold a Data Value, and a
    Display Value, with accessors for each. I have
    overridden the ToString method to display the Display
    value.

    (Two examples that I have seen, including an MS example,
    suggest that the DisplayMember and ValueMember properties
    of the ListBox can be used in this way, I could not get
    it to work using the ListItems.Add method - overriding
    toString() seems to be the only way. Setting Datasource
    may be a different story.)

    When I update the Display value of the underlying object,
    the associated ListBox entry does not update, nor have
    any of my attempts to refresh the list worked.

    Ex:
    ((CustomObject) lstControl.Sele ctedItem).Displ ay = "New
    Display Value"

    The underlying object updates properly. But the ListBox
    continues to show "OLD Display Value" in the control!

    How do I get it to call the ToString() method again for
    that item? Someone has already suggested that I remove
    and then re-add the item, but I do not want to do this if
    I can avoid it - there must be a way to get the ListBox
    to refresh. Help!
  • Zürcher See

    #2
    Re: ListBox Items not Updating/Refreshing

    First there are two ListBox objects: One for Windows Form and one for the
    Web, which ListBox are you talking about?

    Web ListBox use the ListItem object and its property .Text to display it
    Windows Form ListBox accept all the objects and use the .ToString() method
    to display them

    Are you using A Windows Form ListBox with ListItem?

    "gdbjohnson-AT-yahoo-dot-ca-nospamplz" <anonymous@disc ussions.microso ft.com>
    schrieb im Newsbeitrag news:85cc01c495 f1$4df02fe0$a60 1280a@phx.gbl.. .[color=blue]
    > I have a ListBox built of a simple custom object for the
    > ListItems used to be able to hold a Data Value, and a
    > Display Value, with accessors for each. I have
    > overridden the ToString method to display the Display
    > value.
    >
    > (Two examples that I have seen, including an MS example,
    > suggest that the DisplayMember and ValueMember properties
    > of the ListBox can be used in this way, I could not get
    > it to work using the ListItems.Add method - overriding
    > toString() seems to be the only way. Setting Datasource
    > may be a different story.)
    >
    > When I update the Display value of the underlying object,
    > the associated ListBox entry does not update, nor have
    > any of my attempts to refresh the list worked.
    >
    > Ex:
    > ((CustomObject) lstControl.Sele ctedItem).Displ ay = "New
    > Display Value"
    >
    > The underlying object updates properly. But the ListBox
    > continues to show "OLD Display Value" in the control!
    >
    > How do I get it to call the ToString() method again for
    > that item? Someone has already suggested that I remove
    > and then re-add the item, but I do not want to do this if
    > I can avoid it - there must be a way to get the ListBox
    > to refresh. Help![/color]


    Comment

    • Guest's Avatar

      #3
      Re: ListBox Items not Updating/Refreshing

      It's a Windows Form:
      This is how I add my DegreeLst object:
      lstDegree.Items .Add(new DegreeLst(degre eID,
      displaystring)) ;

      g

      [color=blue]
      >-----Original Message-----
      >First there are two ListBox objects: One for Windows[/color]
      Form and one for the[color=blue]
      >Web, which ListBox are you talking about?
      >
      >Web ListBox use the ListItem object and its[/color]
      property .Text to display it[color=blue]
      >Windows Form ListBox accept all the objects and use[/color]
      the .ToString() method[color=blue]
      >to display them
      >
      >Are you using A Windows Form ListBox with ListItem?
      >
      >"gdbjohnson-AT-yahoo-dot-ca-nospamplz"[/color]
      <anonymous@disc ussions.microso ft.com>[color=blue]
      >schrieb im Newsbeitrag news:85cc01c495 f1$4df02fe0[/color]
      $a601280a@phx.g bl...[color=blue][color=green]
      >> I have a ListBox built of a simple custom object for[/color][/color]
      the[color=blue][color=green]
      >> ListItems used to be able to hold a Data Value, and a
      >> Display Value, with accessors for each. I have
      >> overridden the ToString method to display the Display
      >> value.
      >>
      >> (Two examples that I have seen, including an MS[/color][/color]
      example,[color=blue][color=green]
      >> suggest that the DisplayMember and ValueMember[/color][/color]
      properties[color=blue][color=green]
      >> of the ListBox can be used in this way, I could not get
      >> it to work using the ListItems.Add method - overriding
      >> toString() seems to be the only way. Setting[/color][/color]
      Datasource[color=blue][color=green]
      >> may be a different story.)
      >>
      >> When I update the Display value of the underlying[/color][/color]
      object,[color=blue][color=green]
      >> the associated ListBox entry does not update, nor have
      >> any of my attempts to refresh the list worked.
      >>
      >> Ex:
      >> ((CustomObject) lstControl.Sele ctedItem).Displ ay = "New
      >> Display Value"
      >>
      >> The underlying object updates properly. But the[/color][/color]
      ListBox[color=blue][color=green]
      >> continues to show "OLD Display Value" in the control!
      >>
      >> How do I get it to call the ToString() method again for
      >> that item? Someone has already suggested that I remove
      >> and then re-add the item, but I do not want to do this[/color][/color]
      if[color=blue][color=green]
      >> I can avoid it - there must be a way to get the ListBox
      >> to refresh. Help![/color]
      >
      >
      >.
      >[/color]

      Comment

      • Guest's Avatar

        #4
        Re: ListBox Items not Updating/Refreshing

        It's a Windows Form:
        This is how I add my DegreeLst object:
        lstDegree.Items .Add(new DegreeLst(degre eID,
        displaystring)) ;

        g

        [color=blue]
        >-----Original Message-----
        >First there are two ListBox objects: One for Windows[/color]
        Form and one for the[color=blue]
        >Web, which ListBox are you talking about?
        >
        >Web ListBox use the ListItem object and its[/color]
        property .Text to display it[color=blue]
        >Windows Form ListBox accept all the objects and use[/color]
        the .ToString() method[color=blue]
        >to display them
        >
        >Are you using A Windows Form ListBox with ListItem?
        >
        >"gdbjohnson-AT-yahoo-dot-ca-nospamplz"[/color]
        <anonymous@disc ussions.microso ft.com>[color=blue]
        >schrieb im Newsbeitrag news:85cc01c495 f1$4df02fe0[/color]
        $a601280a@phx.g bl...[color=blue][color=green]
        >> I have a ListBox built of a simple custom object for[/color][/color]
        the[color=blue][color=green]
        >> ListItems used to be able to hold a Data Value, and a
        >> Display Value, with accessors for each. I have
        >> overridden the ToString method to display the Display
        >> value.
        >>
        >> (Two examples that I have seen, including an MS[/color][/color]
        example,[color=blue][color=green]
        >> suggest that the DisplayMember and ValueMember[/color][/color]
        properties[color=blue][color=green]
        >> of the ListBox can be used in this way, I could not get
        >> it to work using the ListItems.Add method - overriding
        >> toString() seems to be the only way. Setting[/color][/color]
        Datasource[color=blue][color=green]
        >> may be a different story.)
        >>
        >> When I update the Display value of the underlying[/color][/color]
        object,[color=blue][color=green]
        >> the associated ListBox entry does not update, nor have
        >> any of my attempts to refresh the list worked.
        >>
        >> Ex:
        >> ((CustomObject) lstControl.Sele ctedItem).Displ ay = "New
        >> Display Value"
        >>
        >> The underlying object updates properly. But the[/color][/color]
        ListBox[color=blue][color=green]
        >> continues to show "OLD Display Value" in the control!
        >>
        >> How do I get it to call the ToString() method again for
        >> that item? Someone has already suggested that I remove
        >> and then re-add the item, but I do not want to do this[/color][/color]
        if[color=blue][color=green]
        >> I can avoid it - there must be a way to get the ListBox
        >> to refresh. Help![/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...