Updating listview frequently
Hi,
I have a list view to support presence, it has a buddy and his status using (Session Initiation Protocol). I want to update it whenever someone changes his status. What is the best way to update it?
Hi,
I have a list view to support presence, it has a buddy and his status using (Session Initiation Protocol). I want to update it whenever someone changes his status. What is the best way to update it?
No, it's not possible to bind to LV. If you search the web, you’ll find information on how to extend it to allow for data binding. Keep in mind it would just copy all the data from the source and put it into LV, so you might as well populate it manually.
It makes no difference if list is from database or not, works the same with data binding.
Depends on number of records and how often you need to update it. If you have 10-20 records and need to update it few times a minute, just use LV manually. If you have 1000 records, LV might be a little slow.
By the way, how it's relevant to DataTable? DataGrid has nothing to do with DataTable even though DataTable is commonly used as data source for it.
I try this code but it does not work it hangs, I wonder if there any other solution
if (e.Request.Method == SipMethod.Notify){
string tstatus="";GetStatus(e.Request.Body,
ref tstatus);OK ok = new OK();client1.SendResponse(ok, e.Request);
StringBuilder sb = new StringBuilder(e.Request.From.ToString().Remove(0, 5).Split(';')[0]);sb=sb.Replace(
"@here.com>", "");UpdateListView(sb.ToString(), tstatus); //to avoid cross thread operation exception
}
private void UpdateListView(string buddy,string status){
if (listView1.InvokeRequired){
listView1.Invoke(
new ListViewUpdateEventHandler(UpdateListView), new object[] { buddy, status });}
else{
this.listView1.View = View.SmallIcon;this.listView1.SmallImageList = imageList1;ListViewItem item = new ListViewItem(buddy);item.ImageIndex = (
int)Status.online;this.listView1.Items.Add(item);}
I would not do that each time:
this.listView1.View = View.SmallIcon;
this.listView1.SmallImageList = imageList1;
Also, it appears you're not updating items, you're adding them. As status changes, your list would grow indefinitely (unless you’ve omitted code which removes items).
As to hang, you should step through your code with debugger and to see what's going on. I suspect you might have some issues with passing arguments.