Sign in to follow this  

[.net] listView corresponding to treeView deletion problem

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi..when I press a Del key on the listView, the listView item will be deleted and the treeView node with the same name of the listView item will also be deleted. But it only delete the listView item and it also not work well because when I close the application and restart it, the data still exist on the listView. Below is my code, I tried to use for each keyword to iterate through the treeView nodes but I don't know why, on the if block : if(String::Equals(tn->Text,namapeg)) the program iteration won't get inside this block. Was there any mistake with the String comparison? "namapeg" is the listViewItem->Subitem[1]->Text which I got from the listView SelectedIndexChanged event. "namapeg" represents employee name. And also how to do multiple row deletion and delete the treeView nodes as well? Thank you very much. private: System::Void listView1_KeyDown(System:bject^ sender, System::Windows::Forms::KeyEventArgs^ e) { if (e->KeyCode == Keys:elete) //delete listView di treeView juga dihapus dan sebaliknya. { //delete listView items before the file is physically deleted. listView1->Items->RemoveAt(idxlist); listView1->Refresh(); this->Refresh(); //refresh Form. TreeNodeCollection^ tnc = treeView1->Nodes; for each(TreeNode^ tn in tnc) { MessageBox:how(tn->Text); if(String::Equals(tn->Text,namapeg)) { MessageBox:how(tn->Text); tn->Remove(); } } } }

Share this post


Link to post
Share on other sites
You are doing it the hard way. The TreeNodeCollection has a Remove that all you need to do is pass the node you want to remove. Along with the find method you can remove things with ease.

So first just do a find that uses the key value for that node. Then take the node it returns and pass it to the remove method. No work on your part.

theTroll

Share this post


Link to post
Share on other sites
Yes, I have tried it but it did not work. Can you tell me how to use the Find method? I've tried it but it always error because I don't know how to retrieve the return value. I have used array but it asked me to use array with declared size. I don't understand.
Please give me the code example.

Thank you very much.

Share this post


Link to post
Share on other sites
This is not suppose to be intended to be mean, but you are in over your head. These are some pretty basic things. You need to back up and learn the basics before you move on to this. Need to learn to walk before you run.

theTroll

Share this post


Link to post
Share on other sites

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this