c# - How to refresh listbox to bottom seamlessly? -


i try best explain. trying create im chat app , below codes refresh listbox based on push notification , scroll toward bottom. issue each time refreshes, see records flashes top bottom quick milliseconds. how can make in way, seamless similar phone text message?

    private void getjsonobject(string jsonstring)     {          if (jsonstring != null && jsonstring != "")         {              jobject o = jobject.parse(jsonstring);             jarray a1 = (jarray)o["a1"];                 jarray a2 = (jarray)o["a2"];                 jarray a3 = (jarray)o["a3"];                jarray a4 = (jarray)o["a4"];                //g.msgbox("1st hit");              //run following if data exists             if(a1.count>0){                  string thismessage;                  string thislasttimestamp = (string)a4[a4.count - 1];                  //g.msgbox("inside a1.count outside if logic");                  if (lasttimestamp != thislasttimestamp && isusertyping == false)                 {                     imchatdata.removeelements();                      lasttimestamp = thislasttimestamp;                      (int = 0; < a1.count; i++)                     {                         thismessage = httputility.urldecode((string)a2[i]);                          thismessage = thismessage.replace("`", "'");                          imchatdata.addelements(                             (string)a1[i],                             thismessage,                             (string)a3[i],                             (string)a4[i]                         );                      }                      //lvimchat.itemssource = null;                     lvimchat.itemssource = imchatdata.collection;                      //set scroll toward bottom after sending message                      lvimchat.scrollintoview(lvimchat.items[a1.count - 1]);                     lvimchat.focus();                 }              }         } 

the problem keep setting data source line lvimchat.itemssource = imchatdata.collection. shouldn't need this. set source once , update underlying data.

i'm not sure collection type is, suggest using observablecollection<t>. automatically notify listbox when content changes.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -