Board index » delphi » ListView

ListView

I was wondering if anyone could help me out here pls? I have some edit
boxes made on a inventoryform...and the listview is actually on
another form...how do i get the entered datas to display in the
listview? thanks!!! this is really urgent!!!

thanks
justin

 

Re:ListView


On 3 Apr 2003 02:48:51 -0800, j...@hotmail.com (justin) waffled on
about something:

Quote
>I was wondering if anyone could help me out here pls? I have some edit
>boxes made on a inventoryform...and the listview is actually on
>another form...how do i get the entered datas to display in the
>listview? thanks!!! this is really urgent!!!

>thanks
>justin

Assuming the listview isn't private to the other form, you can just
refer to it from anywhere else in your program by putting the name of
the owner form on the front of any reference... Same for any object or
variable.

E.g.

procedure tfrontfrm.something;
var item:tlistitem;
begin
  item:=anotherform.listview1.item.add;
  item.caption:=edit1.text;
  item.subitems.add(edit2.text);
end;

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES

Re:ListView


what do u mean by private to the other forms? as in a global kinda
thingy? how then do i make the listview component (eg report form)
"global" in eg inventory form.
 THANKS SO MUCH!!!!!
Quote
Dodgy <Do...@earth.planet.universe> wrote in message <news:6q5o8vo8lmcsufc8nddb90vpj07ubbl398@4ax.com>...
> On 3 Apr 2003 02:48:51 -0800, j...@hotmail.com (justin) waffled on
> about something:

> >I was wondering if anyone could help me out here pls? I have some edit
> >boxes made on a inventoryform...and the listview is actually on
> >another form...how do i get the entered datas to display in the
> >listview? thanks!!! this is really urgent!!!

> >thanks
> >justin

> Assuming the listview isn't private to the other form, you can just
> refer to it from anywhere else in your program by putting the name of
> the owner form on the front of any reference... Same for any object or
> variable.

> E.g.

> procedure tfrontfrm.something;
> var item:tlistitem;
> begin
>   item:=anotherform.listview1.item.add;
>   item.caption:=edit1.text;
>   item.subitems.add(edit2.text);
> end;

> Dodgy.

Re:ListView


On 3 Apr 2003 17:28:43 -0800, j...@hotmail.com (justin) wrote:

Quote
>what do u mean by private to the other forms? as in a global kinda
>thingy? how then do i make the listview component (eg report form)
>"global" in eg inventory form.
> THANKS SO MUCH!!!!!

Probably your best bet (from the point of view of design) would be to
add a Unit called Global.pas,

- put its name in the Uses list of all other interested Units

- Add :  Var glbListView :TListView;

- in the Init of the Unit containing the real Listview do :-
    Global.glbListView := MyListView;

That way two things point to the same Object

Re:ListView


In article <61a979f4.0304030248.1aa37...@posting.google.com>, j...@hotmail.com

Quote
(justin) writes:
>I was wondering if anyone could help me out here pls? I have some edit
>boxes made on a inventoryform...and the listview is actually on
>another form...how do i get the entered datas to display in the
>listview? thanks!!! this is really urgent!!!

Your problem has two aspects ...

1 How do I get data to put in a TListView

2 How do I refer from one form to another.

1 The displayed rows of a listview are each held as an individual Item in a
collection of ItemS (note the "S" suffix). The MyListView.Items.Add function
returns the new Item. The Item has properties of Caption and SubItems. The
first column is the Caption of the Item, the remaining columns are held in the
SubItems as a TStrings. Each new string of a TStrings is added with the Add
method of the TListItem.SubItems

So code ...

var
  LI : TListItem;
begin
  LI := MyListView.Items.Add;  // add a new row
  LI.Caption := MyEdit1.Text;       // column 1 text
  LI.SubItems.Add(MyEdit2.Text);  // column 2 text
  LI.SubItems.Add(MyEdit3.Text);  // column3 text
  // etc etc

// note MyListView may have been named ListView1 by Delphi, just use that
Delphic name.
// similarly for MyEdit?

2 Unless the MyListView is declared in the in the "private" or "restricted"
part of the form class declaration with the listview (it won''t be if you
dropped the listview on the form in the Delphi IDE) then your other forms can
"see" the listview form if it's unit (.pas file) is declared in the "uses"
clause of the other forms. So in the implementation section of the other form
add ...

uses
  MyLVUnit;  // list view is on form in MyLVUnit.pas

... That's it.

However you must have previously set the listview's ViewStyle to vsReport and
added columns (using the column editor which appears after double-clicking on
the listview in the IDE).

Alan Lloyd
alangll...@aol.com

Re:ListView


hello i actually did this
procedure TAllCDForm.AddMyListItem;
var
  ListItem: TListItem;
begin
   ListItem := AllCDLV.Items.Add
   ListItem.Caption := Inventoryform.CodeEdt.Text;
   ListItem.Subitems.Add(Inventoryform.TitleEdt.Text);
   ListItem.Subitems.Add(Inventoryform.CategoryRG.Items);
   ListItem.Subitems.Add(Inventoryform.PriceEdt.Text);
   ListItem.Subitems.Add(Inventoryform.InStockEdt.Text);
   ListItem.Subitems.Add(Inventoryform.RowEdt.Text);
   ListItem.Subitems.Add(Inventoryform.ColumnEdt.Text);
   ListItem.Subitems.Add(Inventoryform.DescriptionEdt.Text);
   ListItem.Stateindex := 1;  // Or 0 if you prefer
end;

and did the uses thingy on the other form...but it won't compile? it
has the error of AddMyListItem undeclared identifier...HELP?????

Quote
alangll...@aol.com (AlanGLLoyd) wrote in message <news:20030404030834.06747.00000022@mb-fu.aol.com>...
> In article <61a979f4.0304030248.1aa37...@posting.google.com>, j...@hotmail.com
> (justin) writes:

> >I was wondering if anyone could help me out here pls? I have some edit
> >boxes made on a inventoryform...and the listview is actually on
> >another form...how do i get the entered datas to display in the
> >listview? thanks!!! this is really urgent!!!

> Your problem has two aspects ...

> 1 How do I get data to put in a TListView

> 2 How do I refer from one form to another.

> 1 The displayed rows of a listview are each held as an individual Item in a
> collection of ItemS (note the "S" suffix). The MyListView.Items.Add function
> returns the new Item. The Item has properties of Caption and SubItems. The
> first column is the Caption of the Item, the remaining columns are held in the
> SubItems as a TStrings. Each new string of a TStrings is added with the Add
> method of the TListItem.SubItems

> So code ...

> var
>   LI : TListItem;
> begin
>   LI := MyListView.Items.Add;  // add a new row
>   LI.Caption := MyEdit1.Text;       // column 1 text
>   LI.SubItems.Add(MyEdit2.Text);  // column 2 text
>   LI.SubItems.Add(MyEdit3.Text);  // column3 text
>   // etc etc

> // note MyListView may have been named ListView1 by Delphi, just use that
> Delphic name.
> // similarly for MyEdit?

> 2 Unless the MyListView is declared in the in the "private" or "restricted"
> part of the form class declaration with the listview (it won''t be if you
> dropped the listview on the form in the Delphi IDE) then your other forms can
> "see" the listview form if it's unit (.pas file) is declared in the "uses"
> clause of the other forms. So in the implementation section of the other form
> add ...

> uses
>   MyLVUnit;  // list view is on form in MyLVUnit.pas

> ... That's it.

> However you must have previously set the listview's ViewStyle to vsReport and
> added columns (using the column editor which appears after double-clicking on
> the listview in the IDE).

> Alan Lloyd
> alangll...@aol.com

Re:ListView


You have to add...

procedure AddMyListItem;

...to the type declaration of TAllCDForm, up near the top.
Did I not mention that in the other thread? Sorry about
that! (I've got a sneaking suspicion this is your first Delphi
program... If so, welcome to the "fold"...)

John H. Hedges

Quote
"justin" <j...@hotmail.com> wrote in message

news:61a979f4.0304050524.586d3665@posting.google.com...
Quote
> hello i actually did this
> procedure TAllCDForm.AddMyListItem;
> var
>   ListItem: TListItem;
> begin
>    ListItem := AllCDLV.Items.Add
>    ListItem.Caption := Inventoryform.CodeEdt.Text;
>    ListItem.Subitems.Add(Inventoryform.TitleEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.CategoryRG.Items);
>    ListItem.Subitems.Add(Inventoryform.PriceEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.InStockEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.RowEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.ColumnEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.DescriptionEdt.Text);
>    ListItem.Stateindex := 1;  // Or 0 if you prefer
> end;

> and did the uses thingy on the other form...but it won't compile? it
> has the error of AddMyListItem undeclared identifier...HELP?????

> alangll...@aol.com (AlanGLLoyd) wrote in message

<news:20030404030834.06747.00000022@mb-fu.aol.com>...
Quote
> > In article <61a979f4.0304030248.1aa37...@posting.google.com>,

j...@hotmail.com

- Show quoted text -

Quote
> > (justin) writes:

> > >I was wondering if anyone could help me out here pls? I have some edit
> > >boxes made on a inventoryform...and the listview is actually on
> > >another form...how do i get the entered datas to display in the
> > >listview? thanks!!! this is really urgent!!!

> > Your problem has two aspects ...

> > 1 How do I get data to put in a TListView

> > 2 How do I refer from one form to another.

> > 1 The displayed rows of a listview are each held as an individual Item
in a
> > collection of ItemS (note the "S" suffix). The MyListView.Items.Add
function
> > returns the new Item. The Item has properties of Caption and SubItems.
The
> > first column is the Caption of the Item, the remaining columns are held
in the
> > SubItems as a TStrings. Each new string of a TStrings is added with the
Add
> > method of the TListItem.SubItems

> > So code ...

> > var
> >   LI : TListItem;
> > begin
> >   LI := MyListView.Items.Add;  // add a new row
> >   LI.Caption := MyEdit1.Text;       // column 1 text
> >   LI.SubItems.Add(MyEdit2.Text);  // column 2 text
> >   LI.SubItems.Add(MyEdit3.Text);  // column3 text
> >   // etc etc

> > // note MyListView may have been named ListView1 by Delphi, just use
that
> > Delphic name.
> > // similarly for MyEdit?

> > 2 Unless the MyListView is declared in the in the "private" or
"restricted"
> > part of the form class declaration with the listview (it won''t be if
you
> > dropped the listview on the form in the Delphi IDE) then your other
forms can
> > "see" the listview form if it's unit (.pas file) is declared in the
"uses"
> > clause of the other forms. So in the implementation section of the other
form
> > add ...

> > uses
> >   MyLVUnit;  // list view is on form in MyLVUnit.pas

> > ... That's it.

> > However you must have previously set the listview's ViewStyle to
vsReport and
> > added columns (using the column editor which appears after
double-clicking on
> > the listview in the IDE).

> > Alan Lloyd
> > alangll...@aol.com

Re:ListView


Quote
justin wrote:
> hello i actually did this
> procedure TAllCDForm.AddMyListItem;
> var
>   ListItem: TListItem;
> begin
>    ListItem := AllCDLV.Items.Add
>    ListItem.Caption := Inventoryform.CodeEdt.Text;
>    ListItem.Subitems.Add(Inventoryform.TitleEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.CategoryRG.Items);
>    ListItem.Subitems.Add(Inventoryform.PriceEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.InStockEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.RowEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.ColumnEdt.Text);
>    ListItem.Subitems.Add(Inventoryform.DescriptionEdt.Text);
>    ListItem.Stateindex := 1;  // Or 0 if you prefer
> end;

> and did the uses thingy on the other form...but it won't compile? it
> has the error of AddMyListItem undeclared identifier...HELP?????

You have to call the procedure with its full address:

AllCDForm.AddMyListItem

Re:ListView


AHAHAHAH THANKS SO MUCH!!!! AS A MATTER OF FACT...this is my 2nd
delphi program in 2 years....:P...hehehehe still trying to recall and
things like that..thanks again and being nice and all....really
appreaciate it !!!
God bless
justin
Quote
"JH3" <nobodyinparticu...@jh3.com> wrote in message <news:b6n8vr$81f9$1@news3.infoave.net>...
> You have to add...

> procedure AddMyListItem;

> ...to the type declaration of TAllCDForm, up near the top.
> Did I not mention that in the other thread? Sorry about
> that! (I've got a sneaking suspicion this is your first Delphi
> program... If so, welcome to the "fold"...)

> John H. Hedges

> "justin" <j...@hotmail.com> wrote in message
> news:61a979f4.0304050524.586d3665@posting.google.com...
> > hello i actually did this
> > procedure TAllCDForm.AddMyListItem;
> > var
> >   ListItem: TListItem;
> > begin
> >    ListItem := AllCDLV.Items.Add
> >    ListItem.Caption := Inventoryform.CodeEdt.Text;
> >    ListItem.Subitems.Add(Inventoryform.TitleEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.CategoryRG.Items);
> >    ListItem.Subitems.Add(Inventoryform.PriceEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.InStockEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.RowEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.ColumnEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.DescriptionEdt.Text);
> >    ListItem.Stateindex := 1;  // Or 0 if you prefer
> > end;

> > and did the uses thingy on the other form...but it won't compile? it
> > has the error of AddMyListItem undeclared identifier...HELP?????

> > alangll...@aol.com (AlanGLLoyd) wrote in message
>  <news:20030404030834.06747.00000022@mb-fu.aol.com>...
> > > In article <61a979f4.0304030248.1aa37...@posting.google.com>,
>  j...@hotmail.com
> > > (justin) writes:

> > > >I was wondering if anyone could help me out here pls? I have some edit
> > > >boxes made on a inventoryform...and the listview is actually on
> > > >another form...how do i get the entered datas to display in the
> > > >listview? thanks!!! this is really urgent!!!

> > > Your problem has two aspects ...

> > > 1 How do I get data to put in a TListView

> > > 2 How do I refer from one form to another.

> > > 1 The displayed rows of a listview are each held as an individual Item
>  in a
> > > collection of ItemS (note the "S" suffix). The MyListView.Items.Add
>  function
> > > returns the new Item. The Item has properties of Caption and SubItems.
>  The
> > > first column is the Caption of the Item, the remaining columns are held
>  in the
> > > SubItems as a TStrings. Each new string of a TStrings is added with the
>  Add
> > > method of the TListItem.SubItems

> > > So code ...

> > > var
> > >   LI : TListItem;
> > > begin
> > >   LI := MyListView.Items.Add;  // add a new row
> > >   LI.Caption := MyEdit1.Text;       // column 1 text
> > >   LI.SubItems.Add(MyEdit2.Text);  // column 2 text
> > >   LI.SubItems.Add(MyEdit3.Text);  // column3 text
> > >   // etc etc

> > > // note MyListView may have been named ListView1 by Delphi, just use
>  that
> > > Delphic name.
> > > // similarly for MyEdit?

> > > 2 Unless the MyListView is declared in the in the "private" or
>  "restricted"
> > > part of the form class declaration with the listview (it won''t be if
>  you
> > > dropped the listview on the form in the Delphi IDE) then your other
>  forms can
> > > "see" the listview form if it's unit (.pas file) is declared in the
>  "uses"
> > > clause of the other forms. So in the implementation section of the other
>  form
> > > add ...

> > > uses
> > >   MyLVUnit;  // list view is on form in MyLVUnit.pas

> > > ... That's it.

> > > However you must have previously set the listview's ViewStyle to
>  vsReport and
> > > added columns (using the column editor which appears after
>  double-clicking on
> > > the listview in the IDE).

> > > Alan Lloyd
> > > alangll...@aol.com

Re:ListView


hie all i was just wondering...how do i delete a selected entry in a
listview? as in not ending clearing all my entries in the listview bu
a specific one?

thanks justin

"John of Aix" <j.murphyNOS...@libertysurf.fr> wrote in message <news:b6n97i$75ia3$12@ID-157326.news.dfncis.de>...

Quote
> justin wrote:
> > hello i actually did this
> > procedure TAllCDForm.AddMyListItem;
> > var
> >   ListItem: TListItem;
> > begin
> >    ListItem := AllCDLV.Items.Add
> >    ListItem.Caption := Inventoryform.CodeEdt.Text;
> >    ListItem.Subitems.Add(Inventoryform.TitleEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.CategoryRG.Items);
> >    ListItem.Subitems.Add(Inventoryform.PriceEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.InStockEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.RowEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.ColumnEdt.Text);
> >    ListItem.Subitems.Add(Inventoryform.DescriptionEdt.Text);
> >    ListItem.Stateindex := 1;  // Or 0 if you prefer
> > end;

> > and did the uses thingy on the other form...but it won't compile? it
> > has the error of AddMyListItem undeclared identifier...HELP?????

> You have to call the procedure with its full address:

> AllCDForm.AddMyListItem

Re:ListView


In article <61a979f4.0304060457.6048...@posting.google.com>, j...@hotmail.com

Quote
(justin) writes:
>hie all i was just wondering...how do i delete a selected entry in a
>listview? as in not ending clearing all my entries in the listview bu
>a specific one?

if (MyListView.Selected <> nil) then  // a selection has been made
  MyListView.Items.Delete(MyListView.Selected.Index);

... for the selected item or ...

MyListView.Items.Delete(4);

... for the fifth item.

Alan Lloyd
alangll...@aol.com

Re:ListView


hmmmmmm...okies let's say now that i've have entered to different data
to appear in the listview...and then i have thie deletebtn to want to
delete a specific data from the listview...let's say the row
containing data b.then would it be the same way to do it?

thanks
justin

Quote
alangll...@aol.com (AlanGLLoyd) wrote in message <news:20030406101243.07170.00000009@mb-ci.aol.com>...
> In article <61a979f4.0304060457.6048...@posting.google.com>, j...@hotmail.com
> (justin) writes:

> >hie all i was just wondering...how do i delete a selected entry in a
> >listview? as in not ending clearing all my entries in the listview bu
> >a specific one?

> if (MyListView.Selected <> nil) then  // a selection has been made
>   MyListView.Items.Delete(MyListView.Selected.Index);

> ... for the selected item or ...

> MyListView.Items.Delete(4);

> ... for the fifth item.

> Alan Lloyd
> alangll...@aol.com

Re:ListView


Quote
justin wrote in message <61a979f4.0304061254.ef37...@posting.google.com>...
>hmmmmmm...okies let's say now that i've have entered to different data
>to appear in the listview...and then i have thie deletebtn to want to
>delete a specific data from the listview...let's say the row
>containing data b.then would it be the same way to do it?

There are no rows, there are only TListItems. If you have
a reference to the right one, you can call Delete on it.

BTW, it would help enormously if you worked a bit on writing
your questions in something resembling written English.

Groetjes,
Maarten Wiltink

Re:ListView


oh alright. Sorry if my writing has been abit off. Back to what you
taught me, There's no rows, there are only TListItems right?  Below is
my code on my form which has the listview. The variables are from data
entries from other forms. How then do I reference which listitem i
want to delete with a deletebtn procedure?

procedure TAllCDForm.AddMyListItem;
begin
   ListItem := AllCDLV.Items.Add;
   ListItem.Caption := CDCode;
   ListItem.Subitems.Add(CDTitle);
   ListItem.Subitems.Add(CDDescription);
   ListItem.Subitems.Add(floattostr(CDPrice));
   ListItem.Subitems.Add(inttostr(CDToAdd));
   ListItem.Subitems.Add(CDManufacturer);
   ListItem.Subitems.Add(CDCategory);
   ListItem.Subitems.Add(inttostr(Row));
   ListItem.Subitems.Add(inttostr(Column));
   ListItem.Stateindex := 0;
end;

Quote
"Maarten Wiltink" <maar...@kittensandcats.net> wrote in message <news:3e91b30c$0$49106$e4fe514c@news.xs4all.nl>...
> justin wrote in message <61a979f4.0304061254.ef37...@posting.google.com>...
> >hmmmmmm...okies let's say now that i've have entered to different data
> >to appear in the listview...and then i have thie deletebtn to want to
> >delete a specific data from the listview...let's say the row
> >containing data b.then would it be the same way to do it?

> There are no rows, there are only TListItems. If you have
> a reference to the right one, you can call Delete on it.

> BTW, it would help enormously if you worked a bit on writing
> your questions in something resembling written English.

> Groetjes,
> Maarten Wiltink

Re:ListView


Me again...

If we can assume that CDCode is a unique value, and you
want to delete an item based on that rather than the
*selected* item (in which case AlanGLloyd already
answered the question), then maybe you want to do
something like this...?

procedure TAllCDForm.DeleteBtn(CDCodeToDelete: String);
var itm: TListItem;
begin
  itm := AllCDLV.FindCaption(0, CDCodeToDelete, False, False, False);
  if itm <> nil then itm.Delete;
end;

There's also TListView.FindData, if you want to search on
something else.

John H.

Quote
"justin" <j...@hotmail.com> wrote in message

news:61a979f4.0304071500.32c22930@posting.google.com...
Quote
> oh alright. Sorry if my writing has been abit off. Back to what you
> taught me, There's no rows, there are only TListItems right?  Below is
> my code on my form which has the listview. The variables are from data
> entries from other forms. How then do I reference which listitem i
> want to delete with a deletebtn procedure?

Go to page: [1] [2]

Other Threads