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!

dblclick event

Status
Not open for further replies.

Aslave

Programmer
Jan 16, 2007
5
0
0
MK
Hi all!

I have dbgrid1 with ex: (column1,column2,column3...) and
dbgrid2 with ex: (same columns like in dbgrid1)

my questioon is:

how by clicking the
row or the first fild in row to dbgrid1
this to be presented in dbgrid2 wich is empty...

my point is this:
I have some workers in dbgrid1 and by selcting some of this or duobleclicking this row wic are double clicked
to be presented to dbgrid2

thanks before!






 
Copying data from a grid can be tedious, but unnecessary. When you click the grid, the hooked dataset becomes the current record. Put the second grids dataset in Insert mode and just copy the fields from the dataset of the first grid to the dataset of of the second grid and post it. A refresh of the second grid should reveal them.
 
Ok..
but, I must to do this...
by double cliking one record of the dbgrid1, that recorde to be presented to dbgrid2...

ex : if I have 10 records in dbgrid1, 4 of this I want to be presented in dbgrid2, but with double cliciking
 
you need to clarify
1. is dbgrid2 data bound ?
2. are the 2 grids attached to 2 different tables?
3. are the records from dbgrid1 being added to the table attached to dbgrid2 on double click.

if the 2 grids are attached to 2 tables when you click a row in the dbgrid1 the dataset moves to that record just copy that record to the table of dbgrid2.
Code:
Var CopyData: Variant;
    i: Integer;
begin
 with dbgrid1.DataSource.DataSet do
 begin
  CopyData:= VarArrayCreate([0, FieldCount-1], varVariant);
  for i := 0 to FieldCount-1 do CopyData[i] := Fields[i].Value;
  dbgrid2.DataSource.DataSet.insert;
  for i := 0 to FieldCount-1 do dbgrid2.DataSource.DataSet.Fields[i].Value := CopyData[i];
dbgrid2.DataSource.DataSet.Post; 
 end;
end;

Aaron
 
I appreciate your help very much, thank you ....! :)and sorry if i was'nt so clear in explanation

I made one solution like this for my problem....well double clicking in field 'emb' to the record of dbgrid5...all other dates like name,surnasme, paying etc. I will bring to the dbgrid6...

procedure Tform1.DBGrid5DblClick(Sender: TObject);
begin
if(dbgrid5.SelectedField.fieldname='EMB') then
begin
dbgrid6.DataSource.DataSet.Insert;
dbgrid6.DataSource.DataSet.FieldByName('emb').AsString:=dbgrid5.SelectedField.AsString;
dbgrid6.DataSource.DataSet.FieldByName('name').asstring:=dbgrid5.DataSource.DataSet.fieldbyname('name').AsString;
dbgrid6.DataSource.DataSet.FieldByName('surname').asstring:=dbgrid5.DataSource.DataSet.fieldbyname('surname').AsString;
dbgrid6.DataSource.DataSet.FieldByName('pay').asstring:=dbgrid5.DataSource.DataSet.fieldbyname('pay').AsString;

dbgrid6.DataSource.DataSet.FieldByName('daywork').asstring:=dbgrid5.DataSource.DataSet.fieldbyname('daywork').AsString;



dbgrid6.DataSource.DataSet.FieldByName('komentary').asstring:=dbgrid5.DataSource.DataSet.fieldbyname('komentary').AsString;

end;
end;
 
to make your code nicer.
Code:
var
 a: integer
 myFields: array[0..5] of string = ('emb','name','surname','pay','daywork','komentary');
begin
 for A:=0 to 5 do
  Table2.FieldByName(myFields[A]).AsString := Table1.FieldByName(myFields[A]).AsString;
end;

Aaron
 
Thank you Aaron for your good advice!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top