Jump to content
  • Advertisement
Sign in to follow this  
chrisliando

[.net] listView corresponding to treeView deletion problem

This topic is 3968 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!