|
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 !
|
|
|
|
|
That would also be a clue that what you think is a " is not a ", find out what it is.
modified on Friday, August 15, 2008 9:52 AM
|
|
|
|
|
I found very little about RKLib.Export when searching for it. Does it export to CSV?
In that case, escaping quotation marks with a backslash will not help you at all.
A value in CSV that contains commas (or whatever separator is used), line breaks or quotation marks should be enclosed with quotation marks, and quotation marks are escaped by putting double quotation marks in the value.
If the library doesn't handle escaping at all, you can do something like this:
if (value.indexOfAny(new char[]{ ',', ';', '"', '\x0d', '\x0a'}) != -1) {
value = "\"" + value.Replace("\"", "\"\"") + "\"";
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Hello everyone,
Two basic questions about BeginInvoke in asynchronous model. More specifically I am asking from this URL,
http://msdn.microsoft.com/en-us/library/bb559033.aspx
1.
I am wondering whether there is any benefit to pass an object by reference to BeginInvoke? Since in EndInvoke, the results will be retrieved. So, pass by value is fine? Any benefits to pass by reference in BeginInvoke?
2.
Any needs to pass asyncState parameter? I think we can define enough values in the 1st input parameter to BeginInvoke and then asyncState parameter will become useless?
thanks in advance,
George
|
|
|
|
|
George_George wrote: I am wondering whether there is any benefit to pass an object by reference to BeginInvoke? Since in EndInvoke, the results will be retrieved. So, pass by value is fine? Any benefits to pass by reference in BeginInvoke?
which object are you talking about ? The question doesn't make any sense at all.
George_George wrote: Any needs to pass asyncState parameter? I think we can define enough values in the 1st input parameter to BeginInvoke and then asyncState parameter will become useless?
assyncState will be assigned to IAsyncResult 's AsyncState[^] property. So it is not useless.
|
|
|
|
|
Thanks N a v a n e e t h,
N a v a n e e t h wrote: which object are you talking about ? The question doesn't make any sense at all.
My question is more about asynchronous method call in Web Services scenario. For example,
http://www.codeproject.com/KB/cpp/async_xmlws.aspx[^]
In the beginXXX method, like BeginPrime, there are 3 parameters,
int num, System.AsyncCallback callback, object asyncState
My question is, I think the 3rd parameter is useless, since we can change the 1st parameter to some type which wraps both the 1st and 2nd parameter.
Any comments?
regards,
George
|
|
|
|
|
George_George wrote: My question is, I think the 3rd parameter is useless, since we can change the 1st parameter to some type which wraps both the 1st and 2nd parameter.
That's your case. They have made it generic to support everyones needs. The parameters are clear. asyncState can contain any user state, callBack will be the delegate which calls back. So it's the pattern. BTW, what is the issue you are facing ? Your question looks odd.
|
|
|
|