473,698 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[C#] ListView troubles

3 New Member
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 2789
joedeene
583 Contributor
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 New Member
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 New Member
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
2626
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 am populating listview with more than 200,000 items. It is too slow and tried virtual listview. But that doesnot allow me to add images in the listview. So now trying to list only the page user scrolls to.
0
489
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 am populating listview with more than 200,000 items. It is too slow and tried virtual listview. But that doesnot allow me to add images in the listview. So now trying to list only the page user scrolls to.
4
1839
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 ListView (which is located on my other Tab). Now IF I click on the 2nd Tab... the Info IS to be sorted out - as I've set
2
5306
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 tab page containing the listview (tab's onChange event), fire off your form timer by setting the timer interval (me.timerinterval = 1)
0
2225
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 ("Col1",200,HorizontalAlignment.Left); listview.Columns.Add ("Col2",800,HorizontalAlignment.Left);
7
6443
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 ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
7
14996
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
2
6827
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 form every thing works fine: checking items by code
4
4509
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 is that when clicking on the "Show details" button the ListView for the appropriate row binds in the codebehind and displays the detail data for the selected row. I did something similar with a gridview control previously, but want to be able to...
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.