| View previous topic :: View next topic |
| Author |
Message |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Tue Jul 24, 2007 9:58 am Post subject: [Tutorial] Using ListView! |
|
|
TListView
This is a basic tutorial on how to use ListView.
ListView
Drop a ListView on an empty form and 3 buttons, now lets start.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
NewItem:TListitem;
begin
NewItem := ListView1.Items.Add;
NewItem.Caption := 'Hello';
NewItem := ListView1.Items.Add;
NewItem.Caption := 'again';
NewItem := ListView1.Items.Add;
NewItem.Caption := 'World';
end;
|
With this code we add 3 Items to your ListView, if you try run the program and click on Button1 you'll see that the items is added. Now to make it look even nicer you can drop a ImageList1 on your form and set the height and width to 32x32 and add 3 images with the size 32x32. Then in your Object Inspector (while having ListView marked) you click on LargeImages (It has red text) and choose ImageList1 or whatever you called it. If you run the program now, you will see that it got the images above the text, but if you want to control which icon is used, use this code by adding it after each "Add"
| Code: |
NewItem.ImageIndex := 2;
|
Now you get the image with the number 2 on the place where you want it. You can change the way the ListView shows it data by marking ViewList and choose "ViewStyle" in the object inspector.
If you want the text the Item in the ListView is named in a Edit box, use this code (Hard to explain, try it out yourself)
| Code: |
If ListView1.Selected = nil then exit;
Edit1.Text := ListView1.Selected.Caption;
|
The first line is pretty important. If you try acces the choosen item, without theres any there will be an error, therefor using the first line it will automaticly jump out of the procedure if nothing has been choosen. If theres a choosen item the caption of the Item will get displayed in the edit box.
To delete an item from the ListView is pretty simple, double click button2 and write this:
| Code: |
If ListView1.Selected = nil then exit; //Remeber this now!
ListView1.Selected.Delete;
|
If you want to delete a certain item, it can be done this way:
| Code: |
ListView1.Items[1].Delete;
|
With that code we delete Item number 1. Thats way to easy, so lets try do it a bit more advanced. Set ListView's multiselect to true. That makes us able to select more than 1 item by using Shift and Control. Use the following code to delete the choosen items:
| Code: |
var
i,v:integer;
begin
for i := 0 to ListView1.SelCount - 1 do
begin
V := ListView1.Selected.Index;
ListView1.Items[v].Delete;
end;
|
That covers pretty much it. Tell me if you get any errors and if you like it or not, because it might encourage me to make more tutorials about other features in delphi.
[Credits: www.udvikleren.dk for the codes and teaching me to use ListView!]
Last edited by Kevin on Tue Jul 24, 2007 10:13 am; edited 1 time in total |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Jul 24, 2007 10:12 am Post subject: Re: [Tutorial] Using ListView! |
|
|
nice
| Kevinnn wrote: | TListView
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
NewItem:TListitem
begin
NewItem := ListView1.Items.Add;
NewItem.Caption := 'Hello';
NewItem := ListView1.Items.Add;
NewItem.Caption := 'again';
NewItem := ListView1.Items.Add;
NewItem.Caption := 'World';
end;
|
|
You forgot a semicolon at var's.
|
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Tue Jul 24, 2007 10:13 am Post subject: |
|
|
| oh yea ... Lol. I'll edit it now.
|
|
| Back to top |
|
 |
Simsgy Grandmaster Cheater
Reputation: 0
Joined: 07 May 2007 Posts: 581 Location: My new avatar <3
|
Posted: Fri Jul 27, 2007 11:13 am Post subject: |
|
|
Very nice tut!
I will read it after the Delphi 2007 will be done downloading (3 hours).
GJ.
_________________
|
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Fri Jul 27, 2007 12:18 pm Post subject: |
|
|
thanks alot i appreciate every kind of feedback.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jul 27, 2007 3:41 pm Post subject: |
|
|
Wtf..... ?
dude thanks so much !!! ive allways searched this TuT T_T..
now i know how to use a ListView !, without you i couldnet know ever
please make a next tut when delphi 2008 comes out on how to use buttons, ok ?
P.S - CodeGear's Delphi 2007 sucks.
|
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Fri Jul 27, 2007 3:43 pm Post subject: |
|
|
thanks.
"please make a next tut when delphi 2008 comes out on how to use buttons, ok ?" - is that sarcastic ?
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jul 27, 2007 3:45 pm Post subject: |
|
|
| Kevinnn wrote: | thanks.
"please make a next tut when delphi 2008 comes out on how to use buttons, ok ?" - is that sarcastic ? |
yes.
Kevinnn, i hope you're going to to fill/spam this section with TuT's on how to use all Delphi Objects/Tools/VCL components, no offence, people can just google or learn from www.delphibasics.co.uk
Last edited by DeletedUser14087 on Fri Jul 27, 2007 3:46 pm; edited 2 times in total |
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Fri Jul 27, 2007 3:46 pm Post subject: |
|
|
| so you mean its a noob tut?
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jul 27, 2007 3:46 pm Post subject: |
|
|
| Kevinnn wrote: | | so you mean its a noob tut? |
It is a tut for beginners in delphi.
|
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Fri Jul 27, 2007 3:49 pm Post subject: |
|
|
well at least i have accomplished my goal. Making a tutorial which aint too hard for you, or was it too hard ?
 Joke.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jul 27, 2007 3:51 pm Post subject: |
|
|
| Kevinnn wrote: | well at least i have accomplished my goal. Making a tutorial which aint too hard for you, or was it too hard ?
 Joke. |
Umm...dude.
Why would anyone NOT know how to use a ListView ? every single VCL object is explained to you if you press Fone at Delphi lol.
|
|
| Back to top |
|
 |
KingZero Expert Cheater
Reputation: 0
Joined: 27 Jun 2006 Posts: 103
|
Posted: Fri Jul 27, 2007 7:15 pm Post subject: |
|
|
| Kaspersky wrote: |
P.S - CodeGear's Delphi 2007 sucks. |
You suck too.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Jul 27, 2007 7:40 pm Post subject: |
|
|
| This is good, the list view control is a pain in the ass to work out at first.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Jul 28, 2007 4:24 am Post subject: |
|
|
| KingZero wrote: | | Kaspersky wrote: |
P.S - CodeGear's Delphi 2007 sucks. |
You suck too. |
I didnt made any Delphi software, so i cant suck.
|
|
| Back to top |
|
 |
|