Nate Bross Posted January 19, 2009 Posted January 19, 2009 I have a timer that updates an observablecollection<ClassA> every user defined interval (30 seconds for example). I have a Listbox databound to this collection, and pulling updates automatically works fine. I have a textbox and a button, user selects a different item in list (currently using SelectedIndexChanged), I update the textbox. Can I databind the textbox to a property of the currently selected item in my listbox? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 20, 2009 Author Posted January 20, 2009 I was able to resolve the issue above (I'll post a simplified solution soon). My next, related question is this. How can I force the DataContext to refresh? This is what I'm doing (please stop me if there is a better way) ClassA obj = ((ClassA)listBox1.SelectedItem); obj.Description = "New description"; DataAccessLayer.UpdateClassA(obj); When I fire this code, my database is updated as expected, but the values in my ListBox are NOT updated until I manually refresh. I thought that C# was "byref" by default, so updating as I've done above should cause the ListBox items to refresh, no? Please help! Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 22, 2009 Author Posted January 22, 2009 Just as additional information, the method to update the database is async, so it returns immediatly; I've also set the datacondext = null; and then back to my ObservableCollection and it is not reflecting my update. Any thoughts? Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 22, 2009 Author Posted January 22, 2009 So, I've found several people with the same issue; and nobody seems to have a good solution. http://www.lhotka.net/weblog/CommentView,guid,06f305de-ec32-4e20-b042-171b58f305ae.aspx Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 22, 2009 Author Posted January 22, 2009 I have not exhausted my testing to verify; but I believe I have found a solution. If I set the DataContext = new List<T>(0); and then to my modified datasource this causes the desired behavior; why DataContext = null; does not work is beyond me. A bit more testing and I'll have confirmed that this is the "solution". Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted January 26, 2009 Author Posted January 26, 2009 Turns out that I was fooled by the inconsistency of my problem; however, it still seems that it is ALWAYS one "update" behind. Any thoughts would really be helpful. Thanks. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.