|
hello everybody .
I have a little problem. I have a little problem. I have added the TextboxColumn to the datagridview. I want to add event keyUP to that TextBoxColumn. How can I do this?
please provide some some solution.
|
|
|
|
|
You wouldn't create a KeyUp event for the column, you would need to create the event for a DataGridViewTextBoxCell[^] in that column
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi I am writing a netflow collector in C# and for some or other reason the TcpListener object does not go into a pending state as the netflow packets arrive. Does anybody know of a workaround for this. The code follows
<pre>
using System.IO;
using System.Net;
using System;
using System.Threading;
using N = System.Net;
using System.Collections;
class TalkServ
{
System.Net.Sockets.TcpListener server;
protected String file = "";
protected int port = 4055;
public static void Main(String [] args)
{
TalkServ TS = null;
try
{
TS = new TalkServ(args[0],args[1]);
}
catch (Exception e)
{
Console.WriteLine("\nMust specify a file path as first parameter...\nThe file is used to capture netflow data...");
Console.WriteLine("\nMust specify a port as second parameter...\nThe port is the netflow port...");
}
}
public TalkServ(string f,string p)
{
port = Convert.ToInt32(p);
server = new System.Net.Sockets.TcpListener(port);
file = f;
while (true)
{
server.Start();
if (server.Pending())
{
N.Sockets.TcpClient connection = server.AcceptTcpClient();
Console.WriteLine("Connection made");
BackForth BF = new BackForth(connection,file);
}
}
}
}//end of class TalkServ
class BackForth
{
N.Sockets.TcpClient client;
System.IO.StreamReader SR;
string file;
public BackForth(System.Net.Sockets.TcpClient c,String f)
{
client = c;
file = f;
Thread t = new Thread(new ThreadStart(init));
t.Start();
}
private void run()
{
try
{
string l = "";
while (true)
{
l = SR.ReadLine();
if (l != null)
{
if (!l.Equals(""))
{
StreamWriter writer = new StreamWriter(file, true);
writer.WriteLine(l);
writer.Close();
Console.WriteLine(l);
}
}
}
}
catch (Exception e44) { Console.WriteLine(e44); }
}
private void init()
{
SR = new System.IO.StreamReader(client.GetStream());
Thread t = new Thread(new ThreadStart(run));
t.Start();
}
}
</pre>
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
I found this site called MSDN, it has so many answers, like the following:
Remarks
This non-blocking method determines if there are any pending connection requests. Because the AcceptSocket and AcceptTcpClient methods block execution until the Start method has queued an incoming connection request, the Pending method can be used to determine if connections are available before attempting to accept them.
Wow!
|
|
|
|
|
Yes but this does not answer my question. I know what it is used for I just don't seem to pick up the netflow data with my application. It soesn't pick up any connection. Can anybody help with this.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Stephen Lintott wrote: Yes but this does not answer my question. I know what it is used for I just don't seem to pick up the netflow data with my application.
If you are not sending any data, that will just continue to loop forever.
Stephen Lintott wrote: It soesn't pick up any connection. Can anybody help with this.
I dont know the netflow protocol, you sure it is the correct port and protocol? From what I read it uses UDP or SCTP, neither of which you are using.
|
|
|
|
|
OK now we are getting some where. Could you maby supply a code sample for me. I am new to network programming in C# (Normally java). This would help a great deal just for the UDP connections and so on.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Stephen Lintott wrote: OK now we are getting some where. Could you maby supply a code sample for me.
You are getting somewhere. No, I do not have code off by hand. Best will be for you to figure it out, and learn how to do it. You are studying to become a programmer, right?
Stephen Lintott wrote: This would help a great deal just for the UDP connections and so on.
Look at the UdpClient class, it can send and receive IIRC.
|
|
|
|
|
No I am one... Just trying out .net for a change. Thanks for the help I found some code samples on the net.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
I'd like to deep-copy the ListCollectionView. How can I do that? I have tried several techniques but the most of techniques that I tried are not working. Any idea would be appreciated.
|
|
|
|
|
Deep copy, as in clone the objects too?
|
|
|
|
|
yes but i dont want to have an reference of the original object.
For example ~
List<Person> persons = new List<Person>;
public void populateDataAndBindItToTreeView(){
///.........
}
public void UpdateData(){
List<Person> newPersons = new List<Person>;
/// Do something here.
DeepCopy(persons, newPersons); // will update the persons and treeview.
}
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
|
|
|
|
|
Michael Sync wrote: yes but i dont want to have an reference of the original object.
Which object, the list or the contents? Is Person clonable?
|
|
|
|
|
leppie wrote: Which object, the list or the contents?
Yes. the list of person.
leppie wrote: Is Person clonable?
No.
(Actually, I'm using ListCollectionView instead of List<person> in my project. AFAIK, ListCollectionView is not a clonable )
Thanks.
|
|
|
|
|
Michael Sync wrote: leppie wrote:
Is Person clonable?
No.
Then it will be a shallow clone, with new List<Person>(yourlistcollectionview) , you maybe have to cast/convert the ListCollectionView' IEnumerable to a IEnumerable<Person> first.
|
|
|
|
|
Sorry for making you confused. Let me elaborate it again..
This is our real scenario...
We are using WPF and Data-binding. We are using ListCollectionView to bind the control (e.g. Datagrid, TreeView or etc) ... The reason why we are using ListCollectionView is that it supports sorting, filtering and etc...
So, our code will be like that. Note: We are using MVVM pattern in our project so we dont want to write the code in code-behind. We wrote the most of code in ViewModel and bind that ViewModel with View..
=====
Class
=====
class Person() : INotification {
private int _id;
private string _Name;
private List<pet> myPets = new List<pet>;
public int ID{
///
}
public string Name{
///
}
public List<pet> MyPets{
//
}
//impelementation for INotification.
}
then.. I bind it with TreeView.
===========
View - XAML
===========
<herichical>
Souce="Pet" // child class
...
/>
<datatemplate>
.... Pet.Name />
<treeview> ItemSouce={... personListViewCollection } //personListViewCollection is the object from code below
...
/>
===========
ViewModel
===========
ListViewCollection personListViewCollection ;
void Constructor(){
populateData();
}
void populateData(){
List<person> persons = new List<person>();
Person p1 = new Person();
p1.ID =1;
..
List<pet> pets = new List<pet>();
pets.Add(new Pet(){ ...... } );
pets.Add(new Pet(){ ...... } );
p1.MyPets.AddRange(pets);
person.Add(p1);
/// add p2 p3 p4
///note: // Let's say personListViewCollection.GetHashCode() == 1000100
personListViewCollection = new ListViewCollection(persons);
}
So, those data will be displayed on TreeView.. then, I wanna re-populatethe data.
void reload(){
List<person> newPersons = new List<person>();
Person newP1 = new Person();
newP1.ID =1;
..
List<pet> newPets = new List<pet>();
newPets.Add(new Pet(){ ...... } );
newPets.Add(new Pet(){ ...... } );
newP1.MyPets.AddRange(newPets);
newPersons.Add(newP1);
///HERE is the problem. I dont want the hashcode of personListViewCollection to change.
personListViewCollection = new ListViewCollection(newPersons); //Problem..
}
then, I want to refresh the treeview and display the new data...
Any Idea?
|
|
|
|
|
Iterate through each items in the persons collection, create new items with the same value and add to newPersons . This will be the most easiest way. Something like
foreach(Person person in persons)
{
newPersons.Add(new Person(person.Name,person.Email,...));
} You will have new instances with same value in the newPersons collection. Is this what you are looking for or I got you wrong ?
|
|
|
|
|
(I'm not sure what a "ListCollectionView" is, but I can give some general information on creating a deep-copy of an object graph)
well...there are several approaches you could take. All have their pros and cons...here's one technique.
Mark all of your objects in your object graph with the Serializeable attribute. There are 2 noticeable cons to this technique: One- you have to mark each class individually, so there is a chance that one could be accidentally omitted. Two- You don't want to serialize objects that contain references to external resources (databaseConnections being a prime example)
Your procedure (in pseudo-code)
Create a BinaryFormatter
Create a MemoryStream to store the serialized buffer of your object graph
formatter.Serialize(buffer, source)
return the clone by Deserializing the buffer and applying a C-cast to the stream.
The Serializeable attribute will take care of the rest
The objects in the graph DO NOT have to be ICloneable. The Serializeable attribute is all that is needed. You do, however need to mark anything that you do not want to be contained in the clone as Transient
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: (I'm not sure what a "ListCollectionView" is
ListCollectionView[^]
Yes. Binary Serialization would be great.. I found an example that shows how to deep-copy the object using XmlFormater but that guy said that we should consider using Binary Serialization... But the problem is that there is no [Serializeable] attribute in ListCollectionView. and I can't modify the code since ListCollectionView is a part of .NET framework..
|
|
|
|
|
Hello,
Ok, we've gone round and round on this, so let me place an open question. I have a data table where some field values have this ". e.g. Nail 4".
I need to replace this with \" as they are bringing error on my excel output. How can I access each field value and replace the " with \" ?
Please help me, I'd really appreciate your help.
Let's do this !
|
|
|
|
|
string initial = "\"";
string final = initial.Replace("\"", "\\\""));
|
|
|
|
|
Thanks for that, I have it already. But how do I apply this to all the elements in the table ?
Let's do this !
|
|
|
|
|
You need to use foreach and process each row in the table. You may be able to use linq to do an update but I don't know linq yet!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How are you outputting the Excel, what kind of errors do you get, and why do you think that \" should be used to escape the quotation marks?
I would rather expect that "" should be used...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Ok,
I am getting data from a datatable and exporting it to an excel sheet. I was using the RKLib.Export library, however this doesn't handle " quotes in the field values. It displays unintelligible data.
So I decided to use the function I am asking about to clean out the datatable before exporting it.
By the way, do you know where I would get code to export data to excel which handles quotes ?
Let's do this !
|
|
|
|