Yorumları: 356
Konuları: 58
Kayıt Tarihi: 16-12-2018
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 111 Başlangıç
Arkadaşlar Merhaba; Form1 e Edit1 ve birde DBGrid1,DBGrid2 ekledim Edit1 de yazdığım "Fatura No" veya "Cari İsimden" Kayıt buldurup DBGrid1 de listeliyorum fakat 2. bir DBGrid2 de DBGrid1 de seçtiğim Faturanın Stok Detayını listeliyorum. Şimdi ben bu işlemi sadece DBGrid1 de bitirebilir miyim?
şöyle ki DBGrid1 listedeki "Fatura No" yanında "+" işareti olabilir mi? "+" Tıkladığım da o faturaya ait stok detayı gelsin. Olursa nasıl yapabilirim ? kod örneği var mıdır? Yardımcı olur musunuz?
Yorumları: 176
Konuları: 0
Kayıt Tarihi: 01-09-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 552 Acemi
(12-04-2019, Saat: 04:49)OZCANK Adlı Kullanıcıdan Alıntı: Arkadaşlar Merhaba; Form1 e Edit1 ve birde DBGrid1,DBGrid2 ekledim Edit1 de yazdığım "Fatura No" veya "Cari İsimden" Kayıt buldurup DBGrid1 de listeliyorum fakat 2. bir DBGrid2 de DBGrid1 de seçtiğim Faturanın Stok Detayını listeliyorum. Şimdi ben bu işlemi sadece DBGrid1 de bitirebilir miyim?
şöyle ki DBGrid1 listedeki "Fatura No" yanında "+" işareti olabilir mi? "+" Tıkladığım da o faturaya ait stok detayı gelsin. Olursa nasıl yapabilirim ? kod örneği var mıdır? Yardımcı olur musunuz?
Adding Buttons to DBGrid
Steve Zimmelman
The DBGrid is very handy and provides a convenient interface for most tasks. But you may find that it falls short when you try to implement certain bells and whistles. For example, adding components like SpeedButtons or SpinButtons to your grid could really spice up the application. But how do you do it? Steve Zimmelman offers a simple technique.
To add buttons to a DBGrid, you really need a more flexible DBGrid. So the first step is to subclass the TDBGrid and expose some of its methods and properties (see the code block that follows). In order to place the button in the proper cell coordinate, you'll need to know the current row and the CellRect of the Cell that's being displayed. While you're at it, you could put a wrapper around the DefaultRowHeight property so you can change the grid's row height for a more accommodating look.
The key event that you'll use to display the button is the OnDrawColumnCell. But the event's parameter, Rect (a type of TRect), doesn't always work properly for your needs. That's because the Rect is of the Cell that's being drawn, and you need the Data Cell that's identified by the Row property.
unit DBGridObj;
interface
uses Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms,Grids, dbGrids;
Type
TDBGridObj = class(TDBGrid)
Private
FRowHeight : Integer ;
Protected
Procedure
SetRowHeight(Value:Integer);
Public
// The inherited method is declared as protected.
// Used Reintroduce to hide compiler warnings.
Function CellRect(ACol,Arow : Longint):TRect; Reintroduce;
// Expose Row and Col properties
Property Row ;
Property Col ;
Published
Property RowHeight : Integer
Read FRowHeight Write SetRowHeight ;
End;
procedure Register;
implementation
Uses DB ;
Function TDBGridObj.CellRect(ACol,ARow:Longint):TRect;
Begin
Result := Inherited CellRect(ACol, ARow);
End;
Procedure TDBGridObj.SetRowHeight(Value:Integer);
Begin
If FRowHeight <> Value Then Begin
FRowHeight := Value ;
DefaultRowHeight := FRowHeight ;
// Force Grid to update the RowCount.
// The method I need to call is
// UpdateRowCount, but it's declared
// as private in the parent. This
// calls it by making the grid think it has
// been resized.
If Self.DataLink.Active Then Begin
Perform(WM_SIZE,0,0);
End;
End;
End;
procedure Register;
Begin
RegisterComponents('Custom', [TDBGridObj]);
End;
End.
Now that you have a DBGrid that can accommodate your needs, you can add some buttons to it.
Place the new TDBGridObj on a form and create an OnDrawColumnCell event. Place a SpeedButton anywhere on the form.
The following code is rough, and you may not want to use it exactly as-is in an application, but it provides a good example of how this comes together.
I use the Index property of the Column parameter to identify the Column I want to place the button in. The placement of the button is obtained by some simple calculations based on the Current Data Cell's Rect.
procedure TForm1.DBGridObj1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn;
State: TGridDrawState);
Var DataRect : TRect ;
Begin
// Place the button in the first column.
If (Column.Index = 0) Then Begin
With ButtonDBGrid1 Do Begin
DataRect := CellRect(Column.Index,Row);
End;
// Assign the button's parent to the grid.
If SpeedButton1.Parent <> ButtonDBGrid1 Then
SpeedButton1.Parent := ButtonDBGrid1 ;
// Set the button's coordinates.
// In this case, right justify the button.
If SpeedButton1.Left <> (DataRect.Right - SpeedButton1.Width) Then
SpeedButton1.Left := (DataRect.Right - SpeedButton1.Width) ;
If (SpeedButton1.Top <> DataRect.Top) Then
SpeedButton1.Top := DataRect.Top ;
// Make sure the button's height fits in row.
If (SpeedButton1.Height <> (DataRect.Bottom-DataRect.Top)) Then
SpeedButton1.Height := (DataRect.Bottom-DataRect.Top);
End;
End;
And that's all there is to it! You can use TSpinButtons the same way, with one exception: Set the SpinButton's Ctl3D property to False. Otherwise, it leaves a dark border on the top and bottom lines of the cell.
Using this method, your grids can look like this:
Kaynak : http://www.skzimmelman.com/Articles/buttongrid.htm
Yorumları: 1.660
Konuları: 20
Kayıt Tarihi: 05-08-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 18.981 Üstad
12-04-2019, Saat: 08:53
(Son Düzenleme: 12-04-2019, Saat: 08:55, Düzenleyen: mrmarman.)
@ FiRewaLL doğrusunu önermiş.
İllüzyon ile de mümkün
Bir button bulundurun visible özelliği false olsun görünmesin.
OnDrawColumnCell eventinde eğer (gdSelected in state) ise yani satır seçili ise ve Column index dilediğiniz fatura sütununda ise buttonun left top width height değerlerini RECT (hücrenin konum ve büyüklüğü) ile boyutlandırın ve visible özelliğini true yapın.
Butona basınca da datasource'dan yola çıkıp hangi kayıt seçili ise ilgili faturanın değerlerine ulaşırsınız.
Saygılarımla
Muharrem ARMAN
Yorumları: 11
Konuları: 3
Kayıt Tarihi: 27-03-2018
Aktif Kullandığınız Delphi Sürümü:
- Delphi 10.3
- Delphi 10.2
- Delphi XE7
- Delphi XE5
- Delphi 7
Rep Puanı: 19 Başlangıç
Master - Detail konusuna bakmanı öneririm. Bunu devexpress , tms gibi gridler ile kolayca çözebilirsin.
burada örneği var :
https://www.devexpress.com/Support/Cente...le-project
Yorumları: 1.660
Konuları: 20
Kayıt Tarihi: 05-08-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 18.981 Üstad
@ emrgln zaten @ OZCANK master detail ile hallettiğini uygulama şekliyle ifade etmiş.
Detail kısmını sürekli değil de bir button aracılığıyla göstermek istemiş.
Önerinizde de aslında haklısınız, belirttiğiniz bileşenlerde bu tip button özellikleri barındırılıyor. Ücretsiz çözümleri paylaştık, sizinki de iyi birer alternatif.
Saygılarımla
Muharrem ARMAN
Yorumları: 820
Konuları: 135
Kayıt Tarihi: 07-12-2017
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 3.030 Uzman
@ OZCANK peki Grid1 üzerinde bir butona basılınca Grid2 'yi mouse'un basıldığı satır kısmında bir popup şeklinde göstersen yada Grid2'nin left-Top ayarları ile istediğin yerde göstersen
işini görmez mi?
@ mrmarman dediği gibi biraz İllüzyon
Bu dünyada kendine sakladığın bilgi ahirette işine yaramaz.
Yorumları: 1.381
Konuları: 75
Kayıt Tarihi: 20-03-2017
Aktif Kullandığınız Delphi Sürümü:
- Delphi 10.3
- Delphi 10.2
- Delphi 7
- Lazarus / FPC
Rep Puanı: 3.849 Uzman
Fatura ve atok uygulamalarinda, kullanicilar fatura iceriginde scrool ile kayitlar arasinda gezmek iater.. popup gibi bir ekranin isini gorecegini sanmam.. cxgris bu iain prof.olarak tam adreai. Fakat ucretli. Bunun haricinde ilk verilen çözüm gayet basarili gorunuyor..
// Bilgi paylaştıkça çoğalır..
Yorumları: 1.660
Konuları: 20
Kayıt Tarihi: 05-08-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 18.981 Üstad
12-04-2019, Saat: 12:27
(Son Düzenleme: 12-04-2019, Saat: 12:29, Düzenleyen: mrmarman.)
Örnek :
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if (DBGrid1.DataSource.DataSet.Active) AND ( NOT DBGrid1.DataSource.DataSet.EOF ) then
begin
Showmessage( DBGrid1.DataSource.DataSet.FieldByName('M_Name').AsString );
end;
end;
// Burası da button taşıma / görüntüleme kısmı
//-------------------------------------------------------
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
// Buton için uygun column/field hangisisye oraya odaklanacağız...
if ( Field.FieldName ='Btn' ) then
begin
if ( Field.DataSet.RecordCount > 0 ) then
begin
// Kayıt Seçili ve Odaklı ise Butonu yerleştir.
If ( (gdSelected in State) or (gdFocused in State) ) then
begin
BitBtn1.Height := Rect.Bottom-Rect.Top +2;
BitBtn1.Width := Rect.Right -Rect.Left;
BitBtn1.Left := Rect.Left + tDBGrid(Sender).Left + 1;
BitBtn1.Top := Rect.Top + tDBGrid(Sender).Top;
BitBtn1.Visible := True;
BitBtn1.BringToFront;
end;
end;
end;
end;
Saygılarımla
Muharrem ARMAN
Yorumları: 176
Konuları: 0
Kayıt Tarihi: 01-09-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 552 Acemi
(12-04-2019, Saat: 12:27)mrmarman Adlı Kullanıcıdan Alıntı: Örnek :
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if (DBGrid1.DataSource.DataSet.Active) AND ( NOT DBGrid1.DataSource.DataSet.EOF ) then
begin
Showmessage( DBGrid1.DataSource.DataSet.FieldByName('M_Name').AsString );
end;
end;
// Burası da button taşıma / görüntüleme kısmı
//-------------------------------------------------------
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
// Buton için uygun column/field hangisisye oraya odaklanacağız...
if ( Field.FieldName ='Btn' ) then
begin
if ( Field.DataSet.RecordCount > 0 ) then
begin
// Kayıt Seçili ve Odaklı ise Butonu yerleştir.
If ( (gdSelected in State) or (gdFocused in State) ) then
begin
BitBtn1.Height := Rect.Bottom-Rect.Top +2;
BitBtn1.Width := Rect.Right -Rect.Left;
BitBtn1.Left := Rect.Left + tDBGrid(Sender).Left + 1;
BitBtn1.Top := Rect.Top + tDBGrid(Sender).Top;
BitBtn1.Visible := True;
BitBtn1.BringToFront;
end;
end;
end;
end;
Draw ile c# da yapmıştım ama Delphide denememiştim.
Draw da gayet başarılı
Yorumları: 356
Konuları: 58
Kayıt Tarihi: 16-12-2018
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 111 Başlangıç
(12-04-2019, Saat: 18:31)Arkadaşlar Emeğinize Yüreğinize sağlık mrmarman yayınladığı kodu denedim tam istediğim gibi olmayınca bıraktım. Hepinize çok teşekkür ediyorum alakanızdan dolayı. FiRewaLL Adlı Kullanıcıdan Alıntı: (12-04-2019, Saat: 12:27)mrmarman Adlı Kullanıcıdan Alıntı: Örnek :
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if (DBGrid1.DataSource.DataSet.Active) AND ( NOT DBGrid1.DataSource.DataSet.EOF ) then
begin
Showmessage( DBGrid1.DataSource.DataSet.FieldByName('M_Name').AsString );
end;
end;
// Burası da button taşıma / görüntüleme kısmı
//-------------------------------------------------------
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
// Buton için uygun column/field hangisisye oraya odaklanacağız...
if ( Field.FieldName ='Btn' ) then
begin
if ( Field.DataSet.RecordCount > 0 ) then
begin
// Kayıt Seçili ve Odaklı ise Butonu yerleştir.
If ( (gdSelected in State) or (gdFocused in State) ) then
begin
BitBtn1.Height := Rect.Bottom-Rect.Top +2;
BitBtn1.Width := Rect.Right -Rect.Left;
BitBtn1.Left := Rect.Left + tDBGrid(Sender).Left + 1;
BitBtn1.Top := Rect.Top + tDBGrid(Sender).Top;
BitBtn1.Visible := True;
BitBtn1.BringToFront;
end;
end;
end;
end;
Draw ile c# da yapmıştım ama Delphide denememiştim.
Draw da gayet başarılı
|