|
I try to copy a TreeViewItem with all of it's items from a TreeView. When I try to paste it in the same TreeView but in an other location, I stumble on an error. This is my sample of the relevant code:
Some usefull datatypes
TreeView tvFolders;
TreeViewItem bufferFolder;
The method to copy the selected TreeViewItem
private void Copy(object sender, RoutedEventArgs e)
{
if (tvFolders.SelectedItem == null)
return;
bufferFolder = tvFolders.SelectedItem as TreeViewItem;
}
The method to paste the selected TreeViewItem
private void Paste(Object sender, RoutedEventArgs e)
{
if (bufferFolder == null || tvFolders.SelectedItem == null)
return;
TreeViewItem selectedFolder = tvFolders.SelectedItem as TreeViewItem;
selectedFolder.Items.Add(bufferFolder);
}
When I try to execute the selectedFolder.Items.Add(bufferFolder); instruction in the Paste() method, I get an InvalidOperationException with this following message:
"Element already has a logical parent. It must be detached from the old parent before it is attached to a new one."
The only way I know to "detach" the TreeViewItem is to remove it in Copy() method. But doing that actually redesigns the Copy() method to my Cut() method. That is not what I want, but it makes the Paste() method to work
I have tried several ways to copy the TreeViewItem with: "deep copy", "shallow copy", a derivided class of TreeViewItem with Serializable attribute and ISerializable interface as well as using the ICloneable interface but I have not had any luck.
Any suggestions for a soluation?
|
|
|
|
|
You are approaching the problem in the wrong way. Basically, what you need to do is to take a copy of the data that makes up the TreeViewItem that you are interested in, and add this into the relevant location instead. As you have found, each element can only have one parent (the Visual and Logical Trees are tree structures after all), and it takes some extreme hackery to accomplish the "reparenting". By doing things the MVVM way instead, you will make things a lot easier on yourself.
|
|
|
|
|
Yes, I thought I was approaching this in a wrong way.
But how do I copy of all data that is within each TreeViewItem?
It's rather tidious to pass all properties to a new instance of a TreeViewItem from the one I would like to copy/clone.
Any example?
|
|
|
|
|
|
Is it possible to do Video streaming using C# handler
Expression blend 4 with VS2010 C# handler
|
|
|
|
|
It is quite possible. If you are using Expression Blend 4 I assume you are using WPF or Silverlight.
Video streaming is possible in both WPF and Silverlight.
See here[^] for a simple example.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
i am looking for something that is able to stream a video from for example,
i uploaded this video onto the server
www.xxxxx.com/video.wmv
how do i stream it on click event handler, for it to stream this specific video onto the media element on expression blend 4
|
|
|
|
|
I am developing file transfer program on C#.I want to use http protocol but don't know how?
|
|
|
|
|
you could turn at least one machine into a web server, see e.g. this article: http://www.codeproject.com/KB/IP/CSHTTPServer.asxp[^].
And all machines could be web clients, based on either a WebBrowser Control, or the WebClient class, or the HttpRequest and HttpResponse classes.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thanks a lot..if you know the another link,program or source, please share it 
|
|
|
|
|
you're welcome.
MSDN holds all the information on the classes I mentioned.
And I suggest you look around for more articles here on CodeProject, and don't forget to use Google.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
i'm doing this in the .net CF 3.5.
i created a custompanel inherited by form.panel. but when trying to dock the custompanel into form at runtime , i set it's Dock property
to DockStyle.fill, but still the custompanel adds to the form with the small size(100,100). and the onresize event is fired.
any idea how to handle this
thanx in advance.
|
|
|
|
|
You may get a better response by posting this in the Mobile forum
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hello,
I deveopped a web application with Visual Studio 2008.My database is elaborated with Navicat 8 for Mysql.
I want to connect to my db.I have this connection string;
string ConnectionString= "Driver={Navicat 8 for MySQL};"
+ "Server=localhost:3306;" + "Database="+informations+";" + " UID=root;" + "PASSWORD=root";
when I run,it show me this error:
"informations doesn't exist in the current context",informations is my database's name.
I think that I miss to add connection from my project(Tools--->connect to database"),this doesn't show any thing to help me because i couldn't add my database.
Someone to help me is so grantful
ty 
|
|
|
|
|
What it is saying is the the variable "informations" does not exist in the current method as a local variable, or as a parameter,and that it does not exist at the class level either.
Have you recently moved the code from one method to another?
Or should "informations" be inside the string:
string ConnectionString= "Driver={Navicat 8 for MySQL};"
+ "Server=localhost:3306;" + "Database=informations;" + " UID=root;" + "PASSWORD=root";
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Please don't attempt to bump your post. It's disrespectful.
Original post here[^].
|
|
|
|
|
you are getting error "information doesn't esist in the current context" because you've not created any location holder(variable) of information. as you mention "information" is your database Name then OriginalGriff pointed you a perfect answer you should put it inside as "Database =information"
for more details you can go there[^] to learn basic of creating connection
|
|
|
|
|
Hi,
I have a huge set of text files each being 100 kb to 1 mb. My Application reads the files (only 1 at a time) and process the string in it.
My problem is the total size of files are are very large. Is there any way, we can store the files in some format which takes lesser disk space. eg. byte array, or something...
Currently, I have zipped the files and reading the zipped file from my application. Is there any better way to do so.
Thanks,
|
|
|
|
|
Hi Anurag,
You should consider using an MSSQL Compact Database. This is a database that is stored in a single file.
A database will generally store very large amounts of small data extremely efficiently - as well as providing a very rapid way to query that data.
Certainly worth considering - although without more information about what the data is, it's tricky to know!
If a database isn't suitable, then you will get a size decrease and performance increase if you use a binary file format rather than a text file format.
Also note that it can be rather inefficient space-wise to have lots and lots of small files, so again finding some way to aggregate the data into a larger file that can be rapidly accessed may be good.
|
|
|
|
|
Anurag Gandhi wrote: Is there any better way to do so.
No.
Unless you have very particular definitions for better and process.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
By "Better", by default I mean to say "Better by Performance (In terms of disk space, Time consumed and CPU utilization)".
Every time we may not explain each of our words.
|
|
|
|
|
Anurag Gandhi wrote: Better by Performance (In terms of disk space, Time consumed and CPU utilization)
so if I can do it twice as fast at the expense of twice the disk space, is it better or worse?
If you refuse to give sufficient information, don't bother asking in the first place.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Well, I don't wish to argue on this.
Apology, i could not convey my issue properly.
As already mentioned, my issue is disk space.
I can compensate on time consumed, this time, to some extent.
As someone suggested, I liked the database approach as it should take lesser space as well as it will be faster.
Thanks Anyways.
|
|
|
|
|
When disk space is your primary concern:
- I don't see how a database would be more compact than plain text files;
- compression is what you want, ZIP is very good at compressing text (however it takes lots of cycles to decompress).
If you find anything significantly better than ZIP I will be very interested!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Ok, for the time being I will keep the zip aproach only.
I will let you know, in case, i will get better approach.
Thanks for all your help Luc.
|
|
|
|