Mega Code Archive

 
Categories / Delphi / VCL
 

Dbgrid to stringgrid

DbGritToStringGrid Dbgrid den Strin Gride e Seçilen Kayıtları Alma { Program çalışıyor Yanlız dbgride kaç tane alan varsa for döngüsü o kadar artırılmalı. Benim yazdığım denemede dbgrid de 1 tane alan vardı Onun çin for i := 0 to 0 yazıdm 10 alanlı bir alan için for i := 0 to 9 olmalı program dbgrid üzerinde iken çift tıkladığınız kayıdı string gride alıyor ahmetdenizin@hotmai.com } unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls; type TForm1 = class(TForm) DBGrid1: TDBGrid; StringGrid1: TStringGrid; ADODataSet1: TADODataSet; ADODataSet1BROS_ACIKLAMA: TWideStringField; DataSource1: TDataSource; Button1: TButton; procedure FormCreate(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; //değişkenler burada tanımlanıyor i,IlkHucre,BasmaSayisi,SatirSayisi,SutunSayisi : integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin BasmaSayisi := 1;//kaç kerere bastı? SatirSayisi := 1;//alınacak satır SutunSayisi := 1;//alınacak stun StringGrid1.RowCount := 1;//hepsi ilk olarak 1 eşitleniyor o değerinde //başlıklar alınacak onu ayrı olarak buttona yazdım end; procedure TForm1.DBGrid1DblClick(Sender: TObject);//çift tıklanan kayıdı al begin // row := 0; for i := 0 to 0 do begin StringGrid1.Cells[i,SatirSayisi] := DBGrid1.Columns.grid.fields[i].text;// end; StringGrid1.RowCount := StringGrid1.RowCount + 1; SatirSayisi := SatirSayisi +1; end; procedure TForm1.Button1Click(Sender: TObject);//başlık bilgilerini at begin // Strgrite de Başlık bilgilerini atıyor. StringGrid1.Width := DBGrid1.Width; StringGrid1.Colcount := DBGrid1.Fieldcount; StringGrid1.RowCount := 2; StringGrid1.Options := StringGrid1.Options + [goediting]; DBGrid1.Options :=DBGrid1.Options - [dgindicator]; StringGrid1.DefaultRowHeight := 18; StringGrid1.FixedCols := 0; for i := 0 to DBGrid1.FieldCount-1 do begin StringGrid1.Colwidths[i] :=DBGrid1.Columns[i].width; StringGrid1.cells[i,0] := DBGrid1.Columns[i].title.caption; end; // Strgrite de Başlık bilgilerini atıyor.* end; end.