I am trying to pass a parameter of type
List<listviewitem></listviewitem>
in a client server environment. When leaving the client side the list contains all the element required with the correct names. On the server side the list arrives with all the items but missing the name.
I am using the name to perform action on the list, so this poses a problem.
Any ideas please?
On th client side I populate a newlist with the required items. Here the items show correctly
List<ListViewItem> newlist = new List<ListViewItem>();
newlist.AddRange(above);
newlist.Add(me);
newlist.AddRange(below);
Welcome.fClient.UpdateList(users, newlist, form);
This calls the server side. Here the userlist arrives with the required items but the name value is lost. Any ideas why?
public string UpdateList(string[] users, List<ListViewItem> userlist, string form)
{
var server = Server.GetInstance();
List<ServerClient> clients;
lock (server.fClients)
{
if (users== null)
clients = new List<ServerClient>(server.fClients.Values);
else
{
clients = new List<ServerClient>(users.Length);
foreach (var name in users)
{
var client = server.fClients.GetValueOrDefault(name);
if (client != null)
clients.Add(client);
}
}
}
foreach (var item in clients)
{
try
{
item.fClient.Updatelist(userlist,form);
}
catch
{
}
}
return null;
}
The server then calls the client side for the selected users
public void UpdateList(List<ListViewItem> userlist)
{
listUsers1.Items.Clear();
foreach (ListViewItem i in userlist)
{
listUsers1.Items.Add(i);
}
}
I'll try to explain a little better.
first code section
users is an array of strings which determines which clients to connect to
this works fine as the system connects correctly
form is the form name to connect to and this also works fine.
newlist is where the problem arises.
This is a list of listviewitems which contain a subitem and imageindex and are named to allow access by name. What I am trying to achieve is that according to the users actions the userlist is ordered in a particular way. ie if a user clicks on a button it moves his position. newlist on the client side achieves this and the last line of code calls the server side.
second code section
When the code arrives here the list has all the items in ie subitems and imageindex but the name property is an empty string
How does this get lost? and how can I solve it?