?
Solved

Ado Query, List View, Display Help, Access edit

Posted on 2006-10-23
7
Medium Priority
?
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 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