Jump to content
  • Advertisement
Sign in to follow this  

[.net] Build treeView nodes from Text File (CSV Format) does not work

This topic is 3970 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 my name is Chris, I am newb in Visual C++ 2005 Express Edition. I've tried to read from the text file to treeView but it did not work. The treeView was empty. The CSV format is like this: Company name,employee name,age,gender,address,city,zip,phone. This is the data: above is just only the format and they are NOT included in the file. IBM,John,25,Male,1 Rodeo Drive,LA,55555,5550355 Intel,Jim,22,Male,1 Expo Drive,NY,33133,5553434 Intel,Tommy,32,Male,2 Expo Drive,NY,33133,5553322 AMD,Garry,35,Male,24 Main Drive,Seattle,3434,5554444 The point is I only want to fill my treeView with company name and employee name only. The others not. So the treeView would be like this: -ALL <---------------- the main node -IBM <---------------company name -John <------------employee name -Intel <---------------company name -Jim <------------employee name -Tommy <------------employee name -AMD <---------------company name -Garry <---------------employee name it will be like that. there must not be any company and employee name duplication. Isi it possible if someone fix my code below, please? The companyInfo is the class to save all the data to be read into the treeView. The class companyInfor is like this: ref class companyInfo { public: String^ company; public: String^ name; public: String^ age; public: String^ gender; public: String^ address; public: String^ city; public: String^ zip; public: String^ phone; }; Thank you very much. And also when I tried to manage this one: //urus untuk compare dengan listView. TreeNodeCollection^ companynodecollection = treeView1->Nodes; for each (TreeNode^ companynode in companynodecollection) { companynode->Tag = companyInfo; } it also did not work. The error was : 'Assignment1::Form1::companyInfo' : illegal use of this type as an expression //code to read CSV file into treeView nodes private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { String^ fileName = "\\data.txt"; //fullPath = Path::GetFullPath( fileName ); String ^fullPath = String::Concat(Application::StartupPath,fileName); if (!File::Exists(fullPath)) StreamWriter ^sw = File::CreateText( fullPath ); else { StreamReader^ sr = File::OpenText( fullPath ); treeView2->Nodes->Add( gcnew TreeNode("ALL") ); try { String^ buffer = ""; String^ temp; int found = 0; int count = 0; while (buffer=sr->ReadLine()) { temp = buffer; array<Char>^chars = {','}; array<String^>^ arr = temp->Split(chars); IEnumerator^ myEnum = arr->GetEnumerator(); int i = 0; //count word numbers while (myEnum->MoveNext()) { String^ s = safe_cast<String^>(myEnum->Current); //MessageBox::Show(s); //load node treeView di sini! TreeNodeCollection^ companynodecollection = treeView1->Nodes; try { // disabling re-drawing of treeview till all nodes are added treeView1->BeginUpdate(); TreeNode^ parentnode;// = nullptr; TreeNode^ newNode = gcnew TreeNode(); treeView1->Nodes->Clear(); companyInfo ^cinfo = gcnew companyInfo; if (i==0) { //comp name cinfo->company = s; } else if (i==1) { //employee name cinfo->name = s; } else if (i==2) cinfo->age = s; else if (i==3) cinfo->gender = s; else if (i==4) cinfo->address = s; else if (i==5) cinfo->city = s; else if (i==6) cinfo->zip = s; else if (i==7) cinfo->phone = s; TreeNodeCollection^ nodecoll = treeView1->Nodes; if (treeView2->Nodes->Count > 0) { for each (TreeNode^ companynode in companynodecollection) { if(String::Equals(companynode->Text,cinfo->company)) { //child nodes / employee TreeNode^ nextnode = companynode; TreeNodeCollection^ tnc = nextnode->Nodes; for each (TreeNode^ empnode in tnc) { if (!String::Equals(empnode->Text,cinfo->name)) companynode->Nodes->Add(cinfo->name); } } if(!String::Equals(companynode->Text,cinfo->company)) //add as node treeView2->Nodes[0]->Nodes->Add(cinfo->company); } } } //punya try finally { // enabling redrawing of treeview after all nodes are added treeView2->EndUpdate(); treeView2->Refresh(); treeView2->ExpandAll(); } //load node treeView di sini! i++; } //while myEnum count++; } //while buffer } finally { if ( sr ) delete (IDisposable^)sr; } } //else if file exists } [Edited by - chrisliando on December 5, 2007 3:13:29 AM]

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!