Solved

Ado Query, List View, Display Help, Access edit

Posted on 2006-10-23
7
424 Views
Last Modified: 2010-04-05
Hi all I have a list view I use a adoquery that is conected to a access database. database name = mail.mdb. Table= MailInfo.  The code below displays any records based on the text in a combobox. It work great.

var
  colName: string;
begin
  colName:= cmbListName.Text; //Assigns the list name to colName from a combobox
  With QueryManageListView do
  begin
      Close;
      Parameters.ParamByName('pList').Value := colName;
      Open;
      ListView2.Items.Clear;      // Empty the ListView.
      // Loop through the records returned by the query and add the
      // EMail values to the ListView.
     while not EOF do
     begin
       ListView2.Items.Add;
       ListView2.Items[ListView2.Items.Count-1].Caption := FieldByName('Salutation').AsString;
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('FirstName').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('LastName').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Company').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Address1').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Address2').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('City').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('State').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Zip').AsVariant);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Country').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Phone').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Fax').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Email').AsString);

       Next;
     end; { while not EOF do }
     Close;
  end; { With ADOQuery1 do }
I need to be able to doubleclick on the listview2 and be able to edit the info in the Mail.mdb data base.
Thanks for looking or helping.
0
Comment
Question by:Grant Fullen
7 Comments
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17793792
Maybe you can look opn the site : www.torry.ru and do a search for a DBListView and DBTreeView there.

Like: http://www.torry.net/quicksearchd.php?String=dbtreeview&Title=Yes

Best regards,

The Mayor.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17794126
First thing I would do is slightly restructure your code

var
  colName: string;
  lsti: TListItem;
begin
  colName:= cmbListName.Text; //Assigns the list name to colName from a combobox
  With QueryManageListView do
  begin
      Close;
      Parameters.ParamByName('pList').Value := colName;
      Open;
      ListView2.Items.Clear;      // Empty the ListView.
      // Loop through the records returned by the query and add the
      // EMail values to the ListView.
     while not EOF do
     begin
       lsti := ListView2.Items.Add;
       with lsti do
       begin
         Caption := FieldByName('Salutation').AsString;
         SubItems.Add(FieldByName('FirstName').AsString);
         SubItems.Add(FieldByName('LastName').AsString);
         SubItems.Add(FieldByName('Company').AsString);
         SubItems.Add(FieldByName('Address1').AsString);
         SubItems.Add(FieldByName('Address2').AsString);
         SubItems.Add(FieldByName('City').AsString);
         SubItems.Add(FieldByName('State').AsString);
         SubItems.Add(FieldByName('Zip').AsVariant);
         SubItems.Add(FieldByName('Country').AsString);
         SubItems.Add(FieldByName('Phone').AsString);
         SubItems.Add(FieldByName('Fax').AsString);
         SubItems.Add(FieldByName('Email').AsString);
       end;
       Next;
     end; { while not EOF do }
     Close;
  end; { With ADOQuery1 do }


My next question is, what do you want a double click on the listview to actually do.
I know you want to edit the database, but what do you expect to happen.
0
 

Author Comment

by:Grant Fullen
ID: 17795086
Well i have a form named form2. It is a form where you can enter in or edit the record. SO when you click on the highlighted or selected row in the list view it will open form 2 with the current record you seleced in the listview.
Thanks
Grant
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:wildzero
ID: 17799592
Create another TAdoQuery.

When adding items also add
SubItems.Add(FieldByName('ID').AsString);

Where that is the primary key (auto increment). That col doesn't have to display.

On the second AdoQuery have your sql like

SELECT * FROM MailInfo WHERE ID=:SID

Then when you select the item in the listview
set the Parameter of SID of the second TAdo with the  StrToInt(ListView2.items[listview2.selected.item].subitems[12])
then open the database
load all the data from the result of your query and show the form.

That help?
0
 
LVL 10

Accepted Solution

by:
wildzero earned 25 total points
ID: 17799605
If you are going to populate ALL of the data into the listview2, you could just use that data?

ie
If assigned(listview2.selected) then
  begin
     form2.edit1.text := listview2.items[listview2.selected.index].caption;
     form2.edit2.text := listview2.items[listview2.selected.index].subitems[0];
     etc..

     form2.show;
  end;
0
 

Author Comment

by:Grant Fullen
ID: 17799647
Thanks alot that works great.......
0
 
LVL 10

Expert Comment

by:wildzero
ID: 17799655
No problem
also note that you should carry over the ID onto the second form (in a hidden label  / global variable) then when you edit the edit boxes of data you can call

UPDATE MailInfo SET {fields + data} WHERE ID=:SID
Where SID is a parameter set by say,  StrToInt(lbid.caption)

:D
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now