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: -
/**
-
* This fills the ListView with new data. Client is class with getter of
-
* IP adress, client's ID, name and socket. Clients is a Hashtable filled
-
* by instances of Client class (HT Key is (Double)Id, Value (Client)
-
* new Client(...))
-
*
-
* The first loop works fine, if the Client is not in LstvClients, it will be
-
* added.
-
*/
-
foreach (IMServer.Core.Client Client in Clients.Values)
-
{
-
ListViewItem ListItem = new ListViewItem(Convert.ToString(Client.Id));
-
ListItem.Name = Convert.ToString(Client.Id);
-
ListItem.SubItems.Add(Client.Name);
-
ListItem.SubItems.Add(Client.IpAddress);
-
-
if (!LstvClients.Items.ContainsKey(ListItem.Name))
-
{
-
LstvClients.Items.Add(ListItem);
-
}
-
}
-
/**
-
* But this not. It should remove the item of disconnected client
-
* (client isn't in Clients Hashtable, removed by server). This code
-
* remove all clients from ListView.
-
*/
-
foreach (ListViewItem Item in LstvClients.Items)
-
{
-
if (!Clients.ContainsKey(Item.Name))
-
{
-
LstvClients.Items.Remove(Item);
-
}
-
}
-
Thanks for any advice and sorry for my English,
RiZe
3 2789
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
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
|
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
|
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)
|
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);
| |
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...
|
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
|
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
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |