473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

[C#] ListView troubles

3
Hi,
I have a ListView on my server's GUI which is filled with connected clients data and I have to keep this data fresh. For example add new item for new client connection or remove item of disconnected client etc. I wrote this:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * This fills the ListView with new data. Client is class with getter of
  3.  * IP adress, client's ID, name and socket. Clients is a Hashtable filled 
  4.  * by instances of Client class (HT Key is (Double)Id, Value (Client) 
  5.  * new Client(...))
  6.  * 
  7.  * The first loop works fine, if the Client is not in LstvClients, it will be
  8.  * added.
  9.  */
  10. foreach (IMServer.Core.Client Client in Clients.Values)
  11. {
  12.     ListViewItem ListItem   = new ListViewItem(Convert.ToString(Client.Id));
  13.     ListItem.Name           = Convert.ToString(Client.Id);
  14.     ListItem.SubItems.Add(Client.Name);
  15.     ListItem.SubItems.Add(Client.IpAddress);
  16.  
  17.     if (!LstvClients.Items.ContainsKey(ListItem.Name))
  18.     {
  19.         LstvClients.Items.Add(ListItem);
  20.     }
  21. }
  22. /**
  23.  * But this not. It should remove the item of disconnected client 
  24.  * (client isn't in Clients Hashtable, removed by server). This code
  25.  * remove all clients from ListView.
  26.  */
  27. foreach (ListViewItem Item in LstvClients.Items)
  28. {    
  29.     if (!Clients.ContainsKey(Item.Name))
  30.     {
  31.         LstvClients.Items.Remove(Item);
  32.     }
  33. }
  34.  
Thanks for any advice and sorry for my English,
RiZe
Oct 25 '08 #1
3 2775
joedeene
583 512MB
So what exactly are you having trouble with? Are you not able to keep it updated? Are you even getting the items added successfully with the Clients ID or information you want. I just need to know what exactly you're having difficulties with.

joedeene
Oct 25 '08 #2
RiZe
3
First loop add new item to the ListView. The second loop should remove disconnected clients from ListView but it remove the new client too. I will describe on an example.

Application is running and server is listening, no client is connected (Hashtable Clients is clear), no item is in ListView. When client connect to the server, server create his own instance of Client class which is saved to Hashtable (Key (Double)Id of client, (Client) instance of Client class). The first loop will check ListView for clients and add new row with our client (ID 0). The second loop should check if some client disconnected from server and remove his row from ListView but it removes the row of our connected client too so when the client connect the ListView is empty, first loop added his row and the second removed it.
Oct 25 '08 #3
RiZe
3
I got it. ListView.Items.ContainsKey method pass through only String but I was using Double so the solution is converts the key values in Hashtable Clients to String.
Oct 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
4
by: Mr. B | last post by:
VB.net issue here. I've a strange event that I can't seem to figure out... On my Form, I've a TabControl (two Tabs)... On my first tab, I load an Ascii file and dump some info onto my...
2
by: tom | last post by:
Hey All- For those of you having troubles with listviews appearing in the wrong position when on a tab control, we've come up w/one other workaround that may be useful. When you move to the...
0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.