İki Tablo ve İki Form

Firebird ve Interbase veritabanları ve SQL komutlarıyla ilgli sorularınızı sorabilirsiniz. Delphi tarafındaki sorularınızı lütfen Programlama forumunda sorunuz.
Cevapla
spinoza
Üye
Mesajlar: 7
Kayıt: 23 Mar 2004 11:13
Konum: Ankara

İki Tablo ve İki Form

Mesaj gönderen spinoza »

Merhaba,

A formundaki bir DBList Box a, B formundaki bir DBGrid den seçilen verileri aktarmak istiyorum..
A formundaki bir buton aracılığı ile B formu açılıyor (her iki form da MDChild). Açılan B formundaki DBGrid verilerini bir Query den alıyor. Çoklu seçim özelliği açık..Yani kullanıcının seçtiği bütün kayıtları A formundaki DBList e aktarmak istiyorum.. Ama bir türlü yapamadım... Bu konuda yardımcı olabileceklerden yardım bekliyorum...

Sevgi ve selamlarımla.
Kullanıcı avatarı
naile
Admin
Mesajlar: 1873
Kayıt: 11 Haz 2003 10:11

Mesaj gönderen naile »

A formundaki dbListin bağlı olduğu tabloya insert yaparsan eğer ancak görebilirsin, diğer türlü (yani sadece listede görünsün tabloya bişey eklemesin diyorsan) db değil normal List kullanman lazım.
spinoza
Üye
Mesajlar: 7
Kayıt: 23 Mar 2004 11:13
Konum: Ankara

Mesaj gönderen spinoza »

Merhaba,

insert sorun değil...Öğrenmek istediğim dbgrid den çoklu seçimleri nasıl aktarabilirim..? Zaten insert olayını aktarırken yapacağım..Yani esasında dblist e değil de tabloya aktarmak istiyorum,dolayısı ile dblist te de gözükecek..Ancak takıldığım yer, B formundaki dbgrid den çoklu seçimleri nasıl aktaracağım..?

Sevgi ve selamlarımla.
oguzozturk74
Kıdemli Üye
Mesajlar: 574
Kayıt: 01 Şub 2004 12:29
Konum: Erdemli - MERSİN

Mesaj gönderen oguzozturk74 »

Çoklu seçimler için asagıda ki makaleye bir bakın , seçimi yaptıktan sonra
insert ile tabloya kayıt yapabilirsiniz .

TDBGrid and Multi-Selecting Records


Description:
When you add [dgMultiSelect] to the Options property of a DBGrid,
you give yourself the ability to select multiple records within the grid.

The records you select are represented as bookmarks
and are stored in the SelectedRows property.

The SelectedRows property is an object of type TBookmarkList.
The properties and methods are described below.

// property SelectedRows: TBookmarkList read FBookmarks;

// TBookmarkList = class
// public

{* The Count property returns the number of currently
selected items in the DBGrid *}
// property Count: Integer read GetCount;

{* The Clear method will free all the selected records
within the DBGrid and set the Count property to 0 *}
// procedure Clear;

{* The Delete method will delete all the selected rows
from the dataset *}
// procedure Delete;

{* The Find method determines whether a bookmark is
in the selected list. *}
// function Find(const Item: TBookmarkStr;
// var Index: Integer): Boolean;

{* The IndexOf method returns the index of the
bookmark within the Items property. *}
// function IndexOf(const Item: TBookmarkStr): Integer;

{* The Refresh method returns a boolean value to notify
whether any orphans were dropped (deleted) during the
time the record has been selected in the grid. The
refresh method can be used to update the selected list
to minimize the possibility of accessing a deleted
record. *}
// function Refresh: Boolean; True = orphans found


{* The CurrentRowSelected property returns a boolean
value and determines whether the current row is
selected or not. *}
// property CurrentRowSelected: Boolean
// read GetCurrentRowSelected
// write SetCurrentRowSelected;

{* The Items property is a TStringList of
TBookmarkStr *}
// property Items[Index: Integer]: TBookmarkStr
// read GetItem; default;

// end;

Kod: Tümünü seç

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Db, DBTables, StdCtrls;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    btnCount: TButton;
    btnSelected: TButton;
    btnClear: TButton;
    btnDelete: TButton;
    btnSelect: TButton;
    btnGetBookmark: TButton;
    btnFreeBookmark: TButton;
    btnFind: TButton;
    procedure btnCountClick(Sender: TObject);
    procedure btnSelectedClick(Sender: TObject);
    procedure btnClearClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
    procedure btnSelectClick(Sender: TObject);
    procedure btnGetBookmarkClick(Sender: TObject);
    procedure btnFreeBookmarkClick(Sender: TObject);
    procedure btnFindClick(Sender: TObject);
  private
    Bookmark: TBookmark;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

//Example of the Count property
procedure TForm1.btnCountClick(Sender: TObject);
begin
  if DBgrid1.SelectedRows.Count > 0 then
  begin
    ShowMessage(IntToStr(DBgrid1.SelectedRows.Count));
  end;
end;

//Example of the CurrentRowSelected property
procedure TForm1.btnSelectedClick(Sender: TObject);
begin
  if DBgrid1.SelectedRows.CurrentRowSelected then
    ShowMessage('Selected');
end;

//Example of the Clear Method
procedure TForm1.btnClearClick(Sender: TObject);
begin
  DBGrid1.SelectedRows.Clear;
end;
//Example of the Delete Method
procedure TForm1.btnDeleteClick(Sender: TObject);
begin
  DBGrid1.SelectedRows.Delete;
end;


{*
   This example iterates through the selected rows
   of the grid and displays the second field of
   the dataset.

   The Method DisableControls is used so that the
   DBGrid will not update when the dataset is changed.
   The last position of the dataset is saved as
   a TBookmark.

   The IndexOf method is called to check whether or
   not the bookmark is still existent.
   The decision of using the IndexOf method rather
   than the Refresh method should be determined by the
   specific application.
*}

procedure TForm1.btnSelectClick(Sender: TObject);
var
  x: Integer;
  TempBookmark: TBookMark;
begin
  DBGrid1.Datasource.Dataset.DisableControls;
  with DBgrid1.SelectedRows do
  if Count > 0 then
  begin
    TempBookmark := DBGrid1.Datasource.Dataset.GetBookmark;
    for x := 0 to Count - 1 do
    begin
      if IndexOf(Items[x]) > -1 then
      begin
        DBGrid1.Datasource.Dataset.Bookmark := Items[x];
        ShowMessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);
      end;
    end;
    DBGrid1.Datasource.Dataset.GotoBookmark(TempBookmark);
    DBGrid1.Datasource.Dataset.FreeBookmark(TempBookmark);
  end;
  DBGrid1.Datasource.Dataset.EnableControls;
end;

{*
This example allows you to set a bookmark and
and then search for the bookmarked record within
selected a record(s) within the DBGrid.
*}

//Sets a bookmark
procedure TForm1.btnGetBookmarkClick(Sender: TObject);
begin
  Bookmark := DBGrid1.Datasource.Dataset.GetBookmark;
end;
// Free the bookmark
procedure TForm1.btnFreeBookmarkClick(Sender: TObject);
begin
  if Assigned(Bookmark) then
  begin
    DBGrid1.Datasource.Dataset.FreeBookmark(Bookmark);
    Bookmark := nil;
  end;
end;

//Uses the Find method to locate the position of the
//bookmarked record within the selected list in the DBGrid
procedure TForm1.btnFindClick(Sender: TObject);
var
  Index: Integer;
begin
  if Assigned(Bookmark) then
  begin
    if DBGrid1.SelectedRows.Find(TBookMarkStr(Bookmark), Index) then
      ShowMessage('Index in SelectedRows: ' + IntToStr(Index));
  end;
end;

end.
{ Unit1.DFM Source }

Kod: Tümünü seç

object Form1: TForm1
  Left = 206
  Top = 107
  Width = 616
  Height = 459
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 48
    Top = 112
    Width = 505
    Height = 281
    DataSource = DataSource1
    Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgMultiSelect]
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object btnCount: TButton
    Left = 40
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Count'
    TabOrder = 1
    OnClick = btnCountClick
  end
  object btnSelected: TButton
    Left = 144
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Selected'
    TabOrder = 2
    OnClick = btnSelectedClick
  end
  object btnClear: TButton
    Left = 248
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Clear'
    TabOrder = 3
    OnClick = btnClearClick
  end
  object btnDelete: TButton
    Left = 352
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Delete'
    TabOrder = 4
    OnClick = btnDeleteClick
  end
  object btnSelect: TButton
    Left = 464
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Select'
    TabOrder = 5
    OnClick = btnSelectClick
  end
  object btnGetBookmark: TButton
    Left = 144
    Top = 72
    Width = 75
    Height = 25
    Caption = 'GetBookmark'
    TabOrder = 6
    OnClick = btnGetBookmarkClick
  end
  object btnFreeBookmark: TButton
    Left = 248
    Top = 72
    Width = 81
    Height = 25
    Caption = 'FreeBookmark'
    TabOrder = 7
    OnClick = btnFreeBookmarkClick
  end
  object btnFind: TButton
    Left = 344
    Top = 72
    Width = 75
    Height = 25
    Caption = 'Find'
    TabOrder = 8
    OnClick = btnFindClick
  end
  object Table1: TTable
    Active = True
    DatabaseName = 'DBDEMOS'
    TableName = 'employee.db'
    Left = 384
    Top = 360
  end
  object DataSource1: TDataSource
    DataSet = Table1
    Left = 440
    Top = 376
  end
end
spinoza
Üye
Mesajlar: 7
Kayıt: 23 Mar 2004 11:13
Konum: Ankara

Mesaj gönderen spinoza »

Teşekkür ederim.
Cevapla