Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
DBGrid1 Alanlarını Gizle Göster Olarak Kullanmak.
#1
Arkadaşlar Merhaba;  Bir sorunum var ve sizlerden yardım istiyorum.

Delphi7 Kullanıyorum.

Form1 de DBGrid1 var ve Alanlarını isteğe göre gizleyip göstermek istiyorum.

Cari Kod = CARI_KOD
Cari Isim = CARI_ISIM
Stok Kodu = STOK_KODU 
..
..
..
Şeklinde 
PopupMenu Ekledim ve bu alanları da tanımladım. DBGrid1 de sağ klik yapınca Cari Kod a tıkladığımda gizlenmesini tekrar tıkladığım da görünmesini sağlamak istiyorum. 
PopupMenu de Checked özeliği var görünüyorsa işaretli aksi durumda işaretsiz ayarlamaya uğraştım olmadı. Yardımcı olursanız veya fikir verirseniz çok sevinirim.

procedure TForm16.CariKod1Click(Sender: TObject);
var
 i: Integer;
 ColumnIndex: Integer;
begin
 // CariKod1'in Checked durumunu tersine çevir
 CariKod1.Checked := not CariKod1.Checked;

 // CARI_KOD sütununu bul
 ColumnIndex := 0;
 for i := 0 to DBGrid1.Columns.Count - 0 do
 begin
   if DBGrid1.Columns[0].FieldName = 'CARI_KOD' then
   begin
     ColumnIndex := i;
     Break;
   end;
 end;

 // Sütun bulunduysa, Checked durumuna göre gizle veya göster
 if ColumnIndex = 0 then
 begin
   if CariKod1.Checked then
     DBGrid1.Columns[ColumnIndex].Visible := False  // CariKod1 işaretliyse sütunu gizle
   else
     DBGrid1.Columns[ColumnIndex].Visible := True;  // CariKod1 işaretli değilse sütunu göster
 end;
end;

Bu şekilde bir kod yapısı var ama istediğim gibi olmadı.
işaretliyorum gizliyor sonra DBGrid e dönünce tekrar görünüyor anlamadım.
Cevapla
#2
Tam olarak istediğiniz şeymi bilemiyorum ama paylaştığınız kod aşağıdaki şekilde düzenlendiğinde daha sorunsuz hale gelecektir. Smile

procedure TForm16.CariKod1Click(Sender: TObject);
var
 i: Integer;
begin
 // CariKod1'in Checked durumunu tersine çevir
 CariKod1.Checked := not CariKod1.Checked;
 
 // CARI_KOD sütununu bul
 for i := 0 to DBGrid1.Columns.Count - 1 do
 begin
   if DBGrid1.Columns[i].FieldName = 'CARI_KOD' then
   begin
       if CariKod1.Checked then
         DBGrid1.Columns[i].Visible := False  // CariKod1 işaretliyse sütunu gizle
       else
         DBGrid1.Columns[i].Visible := True;  // CariKod1 işaretli değilse sütunu göster
         
         Break;
   end;
 end;
 

end;
Cevapla
#3
Çok teşekkür ederim. Emeğine sağlık. Son birşey ben bu alanları c:\ sürücüsün de AYARLAR.INI dosyasına
[Columns]
CARI_KOD=0
CARI_ISIM=1
PLASIYER_KODU=1

Şeklinde kaydediyorum. Sağ Klik yaptığım da 0 ve 1 e göre Cari Kod un durumunu verebilir miyim ? İşaretli veya İşaretsiz şeklinde.
Cevapla
#4
Mevcut yapınıza göre aşağıdaki şekilde bir yaklaşım ile istediğinizi yapabilirsiniz.

FormCreate de ini dosyasını okuma işlemleini yaptıkdan sonra aşağıdaki şekilde bir yaklaşımla istediğiniz sonuca ulaşabilirsiniz.

// form create de yapılacak işlemler

// ini dosyasından okuma işlemleri

// ini dosyasında CARI_KOD değişken değeri kontrol edilir.
// CariKod1.OnClick eventinde aşağıdaki şekilde NOT (değili) alındığı için
// CariKod1.Checked := not CariKod1.Checked;
// CARI_KOD = 0 ini değeri için  CariKod1.checked := true değeri gönderiliyor.


if CARI_KOD = 0 then
CariKod1.checked := True
else
CariKod1Checked := False;

CariKod1.OnClick(sender);

//.... diğer işlemler
Cevapla
#5
unit my_compenent;

interface

uses
 SysUtils, Classes, Controls, StdCtrls,ComCtrls,Mask, DBCtrls, Buttons,Grids, DBGrids,
  Windows, Messages,  Graphics;



   type
 TDBGrid_Button = class(TDBGrid)
 private
   { Private declarations }
   FRowHeight : Integer ;
  Protected
  Procedure
  SetRowHeight(Value:Integer);
 protected
   { Protected declarations }
 public
Function CellRect(ACol,Arow : Longint):TRect; Reintroduce;
   Property Row ;
   Property Col ;
   { Public declarations }
 published
   { Published declarations }
 Property RowHeight : Integer
  Read FRowHeight Write SetRowHeight ;
    property OnMouseWheel;
 end;


 procedure Register;

implementation

  Function TDBGrid_Button.CellRect(ACol,ARow:Longint):TRect;
Begin
  Result := Inherited CellRect(ACol, ARow);
End;
  Procedure TDBGrid_Button.SetRowHeight(Value:Integer);
Begin
  If FRowHeight <> Value Then Begin
     FRowHeight := Value ;
     DefaultRowHeight := FRowHeight ;
     If Self.DataLink.Active Then Begin
        Perform(WM_SIZE,0,0);
    End;
  End;
End;


procedure Register;
begin

 RegisterComponents('Data Controls', [TDBGrid_Button]);

    end;

end.

kullanımı
bir tane  
checkBox: ekle
  aling atama none olacak 
SpeedButton_Sil_1  checkBox ismini yaz  kolon genişliklerini ayarla 

procedure TKasa1_form.DBGrid_kasa1DrawColumnCell(Sender: TObject;
 const Rect: TRect; DataCol: Integer; Column: TColumn;
 State: TGridDrawState);

  Var DataRect : TRect ;
 Begin               ///  sil buton GÖSTERME
   SpeedButton_sil_1.Visible:=true;
  If (Column.Index = 4) Then Begin
     With DBGrid_kasa1 Do
     Begin
     DataRect := CellRect(Column.Index,Row);
     End;
     If SpeedButton_Sil_1.Parent <> DBGrid_kasa1 Then /// nesle hangi neslenin konrolunde 
     SpeedButton_sil_1.Parent := DBGrid_kasa1 ;
      If (Column.Index = 4)then /// buraya kacıncı sutunda göterilecek 
      If SpeedButton_Sil_1.Left <> (DataRect.Right + Column.Width) Then
         SpeedButton_sil_1.Left := (DataRect.Right + Column.Width) ;
     If (SpeedButton_sil_1.Top <> DataRect.Top) Then
         SpeedButton_sil_1.Top := DataRect.Top ;
     If (SpeedButton_sil_1.Height <> (DataRect.Bottom-DataRect.Top)) Then
     SpeedButton_sil_1.Height := (DataRect.Bottom-DataRect.Top);
     End;

end;
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Projeye dosya olarak eklenmiş dosyanın içeriğini okumak yhackup 9 229 18-04-2025, Saat: 21:39
Son Yorum: bakyuz
  Delphi ile Web Form Alanlarını Doldurma bünyamin68 13 1.017 30-09-2024, Saat: 14:14
Son Yorum: yhackup
  string icinde alt satirda goster koduyla beraber nasil gonderilir sadikacar60 4 355 09-09-2024, Saat: 08:42
Son Yorum: damert6
  SQL de AS Değişkeni kullanmak OZCANK 4 360 08-08-2024, Saat: 11:24
Son Yorum: OZCANK
  Cxgrid Konumunu Dinamik olarak Değiştirmek endmuh 4 1.210 09-12-2023, Saat: 17:49
Son Yorum: endmuh



Konuyu Okuyanlar: 1 Ziyaretçi