1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| TreeView1->Items->Clear() ;
for( int i=0; i < ListBox1->Items->Count; i++ )
{
AnsiString s = ListBox1->Items->Strings[i] ; //récupération d'un élement
AnsiString start = ListBox1->Items->Strings[i][1] ; //récupération du préfixe
bool test = false ;
for( int j=0; j< TreeView1->Items->Count; j++) //parcourt du treeview
{
AnsiString s2 = TreeView1->Items->Item[j]->Text ; //récupération du texte du noeud
if( start == s2 ) // si le noeud correspond au prefixe, on ajoute un sous-element
TreeView1->Items->AddChild( TreeView1->Items->Item[j], s ) ;
if( s2 == s ) //si le noeud est déja existant, on sort
{
test = true ;
break ;
}
}
if( !test ) // si le noeud n'existe pas, on l'ajoute à la racine
TreeView1->Items->Add( TreeView1->Items->GetFirstNode(), s ) ;
} |