• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

Ado Query, List View, Display Help, Access edit

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
Grant Fullen
Asked:
Grant Fullen
1 Solution
 
wimmeyvaertCommented:
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
 
mikelittlewoodCommented:
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
 
Grant FullenAuthor Commented:
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
Industry Leaders: 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!

 
wildzeroCommented:
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
 
wildzeroCommented:
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
 
Grant FullenAuthor Commented:
Thanks alot that works great.......
0
 
wildzeroCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now