Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select name from DBGrid to display data on new form with DBEdits

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
0
0
US
I have a Delphi 7 program that includes a Form with a DBGrid that displays an ADOTable containing an Access file of 3,200 Vietnam veterans. The DBGrid displays the Last Name, First Name and some other fields. I have a search procedure that searches on a Last Name typed into an Edit box. The first occurrence of the Last Name is located. I have a DBGridCellClick procedure that, when the desired veteran’s name is clicked, a new Form is displayed that contains 10 DBEdit boxes congaing several fields from the ADOTable. Each DBEdit box is set to the desired ADOTable field.

Problem:
How do I have the second Form, with the 10 DBEdits, display the data from the selected name from the DBGrid?
 
I have done that. I have a Main Form that is i menu form that selects the Form with the DBGrid. The ADOConnection, ADOTable ans DataSource are on the Main Form. The DBGrid and the DBEditd refer to Form_Main.ADOTable1.
 
Are the dbEdits actually pointing to a Datasource component rather than the ADOTable?

 
In summary:

Datasource is a TDatasource;


DataSource.dataset := ADOTable;

DBEdit.Datasource := Datasource;
DBGrid.Datasource := Datasource;

Any number of DB components can be 'fed' data from a single datasource if you set their Datasource property to your Datasource component.

Is that what you have?
 
I have partially solved the problem. In Form2, with the 10 DBedits, I have added an Edit Search box and a search procedure. I have added the following to the OnActitation Event;

Edit_Search.Text := Form1.Edit_Search.Text

This forces Form2 DBEdits to search on the name entered in the Search Box on Form1. This works.

What I need is for the search to be based on the OnGridClick event, I tried the following to the Form2 OnActivation event;

Edit_Search.Text := Form1DBGrid1.Fields[0].AsString.

This did not work.

I added this to the Form1.DBCellClick event to see if the DBGrid value was being read;

Temp := Form_Member.DBGrid1.Fields[0].AsString;

Temp was blank. I need to read the value from the DBGrid not the DBEdit_Search.

If I can read the value from the DBGrid field my problem will be solved.
 
You need to replace
Edit_Search.Text := Form1DBGrid1.Fields[0].AsString;
with this
Edit_Search.Text := ADOTable1.Fields[0].AsString;

When you click on a row in your DBGrid, it sets that row as the record your ADO table is pointing to, so to get your current record, read it from your ADO table, not from the DBGrid.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top