Reading multiple lines of text
I am stuck at reading the multiple line of text and retrieve the text into a TreeView list. This is the example of the list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
[1]
FamilyName=X
FamilyMembersCount=5
FamilyMembersName=Alex
[2]
FamilyName=X
FamilyMembersCount=5
FamilyMembersName=George
[3]
FamilyName=X
FamilyMembersCount=5
FamilyMembersName=Michael
[4]
FamilyName=X
FamilyMembersCount=5
FamilyMembersName=Andrew
[5]
FamilyName=X
FamilyMembersCount=5
FamilyMembersName=Brian
[6]
FamilyName=Y
FamilyMembersCount=5
FamilyMembersName=Feng
[7]
FamilyName=Y
FamilyMembersCount=5
FamilyMembersName=Wen
[8]
FamilyName=Y
FamilyMembersCount=5
FamilyMembersName=Jun
[9]
FamilyName=Y
FamilyMembersCount=5
FamilyMembersName=Jie
[10]
FamilyName=Y
FamilyMembersCount=5
FamilyMembersName=Xuan
|
I want to add into a TreeView(possible if it's in Borland C++ Builder 2010) With the Parent as X, Child of X is 5 and Child of 5 is the name.
This is my code snippet in RAD Studio 2010
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
struct Family
{
int Number;
string FamilyName;
string FamilyCount;
string MembersName;
};
void GetFamilyData ()
{
ifstream File.open("Database.txt");
while(File.good())
{
Family NewFamily;
string TempString;
getline (File, TempString);
NewFamily.Number = atoi (TempString.substr (1, TempString.length() - 1).c_str());
getline (File, TempString);
NewFamily.FamilyName = TempString.substr (11, TempString.length() - 11);
TTreeNode *tvFamilyName = TreeView1->Items->Add(NULL, UnicodeString((NewFamily.FamilyName).c_str()));
getline (File, TempString);
NewFamily.FamilyCount = TempString.substr (19, TempString.length() - 19);
TTreeNode *tvFamilyCount = TreeView1->Items->AddChild(tvFamilyName, UnicodeString((NewFamily.FamilyCount).c_str()));
getline (File, TempString);
NewFamily.MembersName = TempString.substr (18, TempString.length() - 18);
TTreeNode *tvMembersName = TreeView1->Items->AddChild(tvFamilyCount, UnicodeString((NewFamily.MembersName).c_str()));
}
File.close();
}
|
But it doesn't load all the data i have, instead, it loads only the first family data in my Database.txt. Can someone tell me what happened?
I really need this urgent, can someone help me? Or this isn't a correct place to ask this?
Hello nerrazzuri,
Maybe you should post it in the 'Windows Programming' forum.
This is an example for c# which is similar
1 2 3 4 5 6 7 8 9 10 11
|
// Populates a TreeView control with example nodes.
private void InitializeTreeView()
{
treeView1.BeginUpdate();
treeView1.Nodes.Add("Parent");
treeView1.Nodes[0].Nodes.Add("Child 1");
treeView1.Nodes[0].Nodes.Add("Child 2");
treeView1.Nodes[0].Nodes[1].Nodes.Add("Grandchild");
treeView1.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Great Grandchild");
treeView1.EndUpdate();
}
|
Does it help?
Topic archived. No new replies allowed.