Solved

Ado Query, List View, Display Help, Access edit

Posted on 2006-10-23
7
425 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

12 Experts available now in Live!

Get 1:1 Help Now