Cita:
Empezado por lbidi
En el caso que el usuario necesite crear mas nodos y subnodos al arbol, como puedo hacer
para ir grabando el "nivel" dentro del nodo, para asi luego grabarlo en la bd.? Me explico?
si tengo creados 2 niveles.
01 - Hombres
02 - Mujeres
y el usuario me crea un nivel dentro de hombres, quedaria
01 - Hombres
0101 - Pantalones <-- como saber que numero asignarle a este nivel? y los sucesivos?
02 - Mujeres
|
Hola Ibidi.
Bueno, en ese caso usando
TStrings nos quedamos cortos...
Fijate si te sirve este ejemplo:
Código Delphi
[-]
uses Contnrs;
type
TClase = class(TObject)
Nivel: string;
Texto: string;
Level: string;
end;
var
ObjLst: TObjectList;
Clase: TClase;
procedure TForm1.FormCreate(Sender: TObject);
var
nodo0,nodo1,nodo2,nodo3,nodo4: TTreeNode;
begin
ObjLst:= TObjectList.Create;
nodo0:= tvCatalogo.Items.AddFirst(nil, 'ARTICULOS');
while not Qry_Cata.Eof do
begin
Clase:= TClase.Create;
ObjLst.Add(Clase);
Clase.Nivel:= Qry_Cata.FieldByName('Nivel').AsString;
Clase.Texto:= Qry_Cata.FieldByName('Texto').AsString;
Clase.Level:= '01';
case Length(Clase.Nivel) of
2: nodo1:= tvCatalogo.Items.AddChildObject(nodo0,Clase.Texto,Clase);
4: nodo2:= tvCatalogo.Items.AddChildObject(nodo0,Clase.Texto,Clase);
6: nodo3:= tvCatalogo.Items.AddChildObject(nodo0,Clase.Texto,Clase);
8: nodo4:= tvCatalogo.Items.AddChildObject(nodo0,Clase.Texto,Clase);
end;
Qry_Cata.Next;
end;
tvCatalogo.FullExpand;
end;
procedure TForm1.btnAddNodeClick(Sender: TObject);
var
nodo: TTreeNode;
begin
Clase:= TClase.Create;
ObjLst.Add(Clase);
Clase.Nivel:= 'Nuevo valor nivel';
Clase.Texto:= 'Nuevo valor texto';
with tvCatalogo do
begin
Clase.Level:= TClase(Selected.Data).Level +
StringOfChar('0', 2-Length(IntToStr(Selected.Level+1))) +
IntToStr(Selected.Level+1);
nodo:= Items.AddChildObject(Selected,Clase.Texto,Clase)
end;
end;
procedure TForm1.tvCatalogoClick(Sender: TObject);
begin
with tvCatalogo do
if Assigned(Selected) and (Selected.Level > 0) then
with TClase(Selected.Data) do
Caption:=Format('Nivel: %s ~ Texto: %s ~ Level: %s',[Nivel,Texto,Level]);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ObjLst.Free;
end;
Saludos.