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?

[216 byte] By [Kartit] at [2007-12-25]
# 1

Try use data binding. Also consider replacing LV with DataGrid, it’s more efficient.

IlyaTumanov at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 2

does the datagrid displays icons next to each buddy?

Kartit at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 3

If you override cell painting and draw that icon, sure. NETCF V2 SP1 needed for that.

IlyaTumanov at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 4
is it possible to bind a listview to a data structure instead since the list is not from a database? I would be thankful if you can post a sample code.
Kartit at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 5

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.

IlyaTumanov at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 6
So if I want to implement a window that displays the picture representing the status (online, offline) and next to it the buddy name, it is better to do it using a Datagrid (which does not support pics or icons as opposed to LV) and I should bind it say to a dynamic table in the memory(DataTable). is that what true?
Kartit at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 7

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.

IlyaTumanov at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 8

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);

}

Kartit at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 9

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.

IlyaTumanov at 2007-8-31 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...