Results 1 to 3 of 3

Thread: Databound Listbox SelectedItem

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Databound Listbox SelectedItem

    I have a listbox bound to a datasource, which gets updated.

    When it does the selected index remains the same. Meaning, that the selected item is different, since the order/number of items could change as the datasource is updated.

    Is there any way round this?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Databound Listbox SelectedItem

    Exactly what is the control bound to? Can you provide some example code we can execute to demonstrate the issue?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Databound Listbox SelectedItem

    It's bound to a class derived from BindingList of custom objects, which only every has items added or removed (the list isn't cleared and repopulated).

    All i did was add AddRange / RemoveRange functions as below:
    Code:
    public void AddRange(IEnumerable<T> Items, IEqualityComparer<T> Comparer)
            {
                foreach (T Item in Items)
                {
                    if (!this.Items.Contains(Item, Comparer))
                        this.Items.Add(Item);
                }
                OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0));
            }
    I may have answered my own question. Is this issue caused by me using the Reset listchangedtype enumeration value?
    I used that figuring no others were appropriate since it wasn't just one index that was changing.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width