Hi there everyone,
I have a virtual treeview that I use as a grid and I want to add columns to it dynamically. The data structure is just a dynamic array of string and it is working very well for this purpose. This means that I can increase or decrease the columns in the virtual treeview at will.
The code snippet for column creation and deletion is shown below:
//
if ACreateColumns then
begin
ATree.BeginUpdate;
//intOldColumns := ATree.Header.Columns.Count;
//// Delete the existing columns
//for intGridCol := 0 to Pred(intOldColumns) do
// ATree.Header.Columns.Delete(intGridCol);
ATree.Header.Columns.Clear;
//
for intGridCol := 0 to Pred(intColMax) do
begin
ATree.Header.Columns.Add;
ATree.Header.Columns[intGridCol].Width := 120;
// Column titles - from a JSON array
ATree.Header.Columns[intGridCol].Text := UpCase(StringReplace(jsArrayRow.Objects[0].Names[intGridCol], '_', ' ', [rfReplaceAll]))
end;
//
ATree.Header.Options := ATree.Header.Options + [{hoAutoResize,} hoVisible];
ATree.Header.Height := 26;
//
ATree.Invalidate;
ATree.EndUpdate;
end;
The code above works but the only problem is if I fill the virtual treeview with many columns, then clear it and fill the virtual treeview with fewer columns than before, I can still see the columns I had deleted earlier. It is as if the virtual treeview does not repaint/refresh itself properly.
Can anyone help me figure out what is wrong?
Cheers,
JD