j42
asked on
Customize TListView
Hi,
I use a TListView component to display some data (report style). How can I add the ability to customize it? I want the user to be able to rearrange columns and hide some others. Are there built in features of TListView or do I have to add them myself?
Regards
J
I use a TListView component to display some data (report style). How can I add the ability to customize it? I want the user to be able to rearrange columns and hide some others. Are there built in features of TListView or do I have to add them myself?
Regards
J
Hi J ...
I'll keep it a lil shorter this time :-)
Depends on exactly what you trying to do. If you want to change the appearance of a particular item, column, or draw the whole view yourself to provide graphics and a complete custom look, then you can use these events :
OnDrawItem
-----
OnCustomDraw
OnCustomDrawItem
OnCustomDrawSubItem
-----
OnAdvancedCustomDraw
OnAdvancedCustomDrawItem
OnAdvancedCustomDrawSubIte m
to draw on : listview1.Canvas ... DrawRect, FillRect, etc
(if you need examples [they are lengthy], let me know)
If you just want to be able to hide and show columns then as Geobul suggested, you can choose an appropriate event, and set the column.width = new_value appropriately.
Steve
I'll keep it a lil shorter this time :-)
Depends on exactly what you trying to do. If you want to change the appearance of a particular item, column, or draw the whole view yourself to provide graphics and a complete custom look, then you can use these events :
OnDrawItem
-----
OnCustomDraw
OnCustomDrawItem
OnCustomDrawSubItem
-----
OnAdvancedCustomDraw
OnAdvancedCustomDrawItem
OnAdvancedCustomDrawSubIte
to draw on : listview1.Canvas ... DrawRect, FillRect, etc
(if you need examples [they are lengthy], let me know)
If you just want to be able to hide and show columns then as Geobul suggested, you can choose an appropriate event, and set the column.width = new_value appropriately.
Steve
ASKER
Hi Steve,
nice to hear from you. Did you read the posting of swift99 in my last question. I guess I annoyed him in some way...
> (if you need examples [they are lengthy], let me know)
Thanks for offering. I know how to do it myself, I just want to avoid reinventing the wheel.
Best of luck
J
nice to hear from you. Did you read the posting of swift99 in my last question. I guess I annoyed him in some way...
> (if you need examples [they are lengthy], let me know)
Thanks for offering. I know how to do it myself, I just want to avoid reinventing the wheel.
Best of luck
J
Hi J,
I'm not so sure you annoyed anyone ... everyone has a bad day from time to time ;-)
Speak to ya soon,
Steve
I'm not so sure you annoyed anyone ... everyone has a bad day from time to time ;-)
Speak to ya soon,
Steve
ASKER
Hi,
I am going to answer the question myself. However thanks for beeing helpful. I will split the points.
Points for geobul:
https://www.experts-exchange.com/questions/20541229/Points-for-geobul.html
Points for Steve:
https://www.experts-exchange.com/questions/20541230/Points-for-Steve.html
// Switch two columns
procedure TForm1.Button2Click(Sender : TObject);
const
SOURCE = 2;
DEST = 1;
begin
ListView1.Columns[DEST].In dex := SOURCE;
ListView1.UpdateItems(0, ListView1.Items.Count - 1);
end;
// Remove column
procedure TForm1.Button3Click(Sender : TObject);
var
i: integer;
const
COL = 3;
begin
ListView1.Columns[COL].Des troy;
for i := 0 to (ListView1.Items.Count - 1) do
begin
ListView1.Items[i].SubItem s.Delete(C OL - 1);
end;
end;
Regards
J
I am going to answer the question myself. However thanks for beeing helpful. I will split the points.
Points for geobul:
https://www.experts-exchange.com/questions/20541229/Points-for-geobul.html
Points for Steve:
https://www.experts-exchange.com/questions/20541230/Points-for-Steve.html
// Switch two columns
procedure TForm1.Button2Click(Sender
const
SOURCE = 2;
DEST = 1;
begin
ListView1.Columns[DEST].In
ListView1.UpdateItems(0, ListView1.Items.Count - 1);
end;
// Remove column
procedure TForm1.Button3Click(Sender
var
i: integer;
const
COL = 3;
begin
ListView1.Columns[COL].Des
for i := 0 to (ListView1.Items.Count - 1) do
begin
ListView1.Items[i].SubItem
end;
end;
Regards
J
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use OnColumnClick or OnColumnRightClick to hide a column. Example: when a user right-clicks on a certain column then it gets hidden (it can be restored later by resizing it either in code or manually):
procedure TForm1.ListView1ColumnRigh
Column: TListColumn; Point: TPoint);
begin
Column.Width := 0;
end;
Regards, Geo