Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
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?

XML
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

MIDL
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?
Posted
Updated 24-Feb-11 3:20am
v6
Comments
#realJSOP 24-Feb-11 5:44am    
Do you mean the property is empty, or the property is completely missing?
milenalukic 24-Feb-11 6:29am    
I have a list of listviewitems - sorry the tags messed up what I wrote. When I pass it as a parameter the name property of the listviewitem is removed. All the items are in the list but missing the value for the name parameter. ie the parameter is now an empty string.
Richard MacCutchan 24-Feb-11 7:19am    
Try showing the actual data you are sending, and the code that is used for the transfer. The above description does not really explain clearly what is happening.
Richard MacCutchan 24-Feb-11 8:23am    
You still have not shown the data that is being sent and received, or where the actual transfer takes place. I also notice that you have a try/catch where the catch block is null. This is very foolish as you could be generating all sorts of exceptions which just get ignored.
milenalukic 24-Feb-11 8:26am    
How can I show you the data? I can only see it when debugging!

It's possible that it may not be getting serialized.

Question for you : does the ListViewItem objects have sub-items? If they don't have at least one sub-item, Name will always return an empty string. This is by design.
 
Share this answer
 
v2
Comments
milenalukic 24-Feb-11 10:00am    
Yes I have 2 sub-items a string and an image. How can I check if it is being serialised?
Nish Nishant 24-Feb-11 10:01am    
Write a mock function and try sending just a single object.
Nish Nishant 24-Feb-11 10:01am    
Which is the first sub-item, the string or the image?
milenalukic 24-Feb-11 10:23am    
On form load I create the columns as below

listUsers1.View = View.Details;
listUsers1.FullRowSelect = true;
listUsers1.Columns.Add("Icon", 35, HorizontalAlignment.Left);
listUsers1.Columns.Add("UserNick", 200, HorizontalAlignment.Left);

and then populate the list;

So the first subitem would be the image.


Working on the function now.
Nish Nishant 24-Feb-11 10:38am    
Ok that's the problem. The Name property returns the Name property of the first sub-item which in your case is the Image subitem.
You could pass the data as XML instead of a list objects.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900