Board index » delphi » changing records by clicking on items in a listbox

changing records by clicking on items in a listbox

hello,

i'm currently working on a database program.
in the main form there is a listbox that lists
all records in a table.
now i want to add the ability of opening records
by clicking on an item.

in that listbox i created items as below:
LastName, FirstName
-------------------
Smith, John

i don't want to use an identifier for each item.
i want to change record by these string values:
(lastname, firstname)

i'm using a TTABLE to connect to database.

thanks,
Dan

 

Re:changing records by clicking on items in a listbox


Quote
"Dan" <da...@programmer.net> wrote in message news:3c723a84$1_1@dnews...

> i'm currently working on a database program.
> in the main form there is a listbox that lists
> all records in a table.
> now i want to add the ability of opening records
> by clicking on an item.

> in that listbox i created items as below:
> LastName, FirstName
> -------------------
> Smith, John

> i don't want to use an identifier for each item.
> i want to change record by these string values:
> (lastname, firstname)

> i'm using a TTABLE to connect to database.

If LastName and FirstName is unique then that is no problem, but this is
normally not the case, thus without another unique identifier it is not
possible to select that one record. Since you are using a ListBox, then you
could store a unique integer identifier from each record in the Objects
peoperty of the listbox along with each name.

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
In a tornado, even turkeys can fly. - unknown

Re:changing records by clicking on items in a listbox


"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:

Quote
>If LastName and FirstName is unique then that is no problem

yes, LastName and FirstName are unique, so i think that
another unique field for identication isn't required.

but also i don't know how to search records to find the
related one to the selected item in the list box.

if you can plz help me to do so.

thanx,
Sean

Re:changing records by clicking on items in a listbox


"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:

Quote
>If LastName and FirstName is unique then that is no problem

yes, LastName and FirstName are unique, so i think that
another unique field for identication isn't required.

but also i don't know how to search records to find the
related one to the selected item in the list box.

if you can plz help me to do so.

thanx

Re:changing records by clicking on items in a listbox


Quote
"Dan" <da...@programmer.net> wrote in message news:3c72b78c$1_1@dnews...

> "Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:
> >If LastName and FirstName is unique then that is no problem

> yes, LastName and FirstName are unique, so i think that
> another unique field for identication isn't required.

> but also i don't know how to search records to find the
> related one to the selected item in the list box.

If you are using a TTable to load up the listbox, then you can use the same
TTable to display the entire record. By far the easiest way to do this is to
trade the listbox for a DBGrid. You can edit the columns in the DBGrid to
display only the fields you want there (i.e. LastName, FirstName). By doing
this you do not need to do any locating - when a user clicks on a row of the
DBGrid, the TTable will be set to that record - attaching other data-aware
control (on the same form or any other form) to this same TTable will
automatically show values from the correct record.

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
In a tornado, even turkeys can fly. - unknown

Re:changing records by clicking on items in a listbox


"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote:

Quote
>By far the easiest way to do this is to
>trade the listbox for a DBGrid.

dear friend,
i know this way, but i want to upgrade my knowledge in this
case.

my DB has a primary key that is created by merging LastName
and FirstName fields.
now my listbox (or any other non-DB-controls) contains all
values of these fields.
so, when i try to change the pointer to the selected item,
i should search through the database, but i don't know how?

plz tell me the solution of this problem, without refering
to the other DB-controls.

thanx,
Dan

Re:changing records by clicking on items in a listbox


Quote
"Dan" <da...@programmer.net> wrote in message news:3c734a62$1_1@dnews...

> my DB has a primary key that is created by merging LastName
> and FirstName fields.
> now my listbox (or any other non-DB-controls) contains all
> values of these fields.
> so, when i try to change the pointer to the selected item,
> i should search through the database, but i don't know how?

> plz tell me the solution of this problem, without refering
> to the other DB-controls.

If last and first names are separate fields in the database then when user
selects item from list box you will need to parse the name back into two
string variables.

You have a choice of using a TTable and setting the Filter property:
    Table1.Filter := 'LastName=' + LastNameVar + ' and FirstName=' +
FirstNameVar;
    Table1.Filtered := True;

... or using a TQuery with an SQL statement:
  Query1.SQL.Text := 'select * from yourtable where LastName=' + LastNameVar
+ ' and FirstName=' + FirstNameVar;
  Query1.Open;

--
Wayne Niddery (Logic Fundamentals, Inc.)
RADBooks: http://www.logicfundamentals.com/RADBooks/delphibooks.html
In a tornado, even turkeys can fly. - unknown

Other Threads