Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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!

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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".

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...