Arsip: Memberisihkan checkbox di treeview yg sudah di klik

 
user image
more 13 years ago

onsir

bagaimana cara memberisihkan chekbox yg sudah tercentang di suatu treeview. misal chekbox tsb sudah di klik dan tercentang lalu saya ingin membersihkan checkbox tsb. berikut ini adalah kode nya :

unit uPemakai;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, ComCtrls, StdCtrls, ImgList, DB, ZAbstractRODataset,
 ZAbstractDataset, ZDataset, Grids, DBGrids;
Type
	TStructure=Packed record
		Fieldname:String[25];
		Level:Integer;
		Tablename:string[25];
		Aliasname:String[25];
		tablealias:string[2];
end;

type
  TFPemakai = class(TForm)
   ImageList1: TImageList;
    TreeView1: TTreeView;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TreeView1Click(Sender: TObject);
    procedure TreeView1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure TreeView1Collapsing(Sender: TObject; Node: TTreeNode;
      var AllowCollapse: Boolean);
  
  private
    { Private declarations }
  public
    { Public declarations }
    tn : TTreeNode;
    P:TPoint;
  end;
const
//ImageList.StateIndex=0 has some bugs, so we add one dummy image to position 0
cFlatUnCheck = 1;
cFlatChecked = 2;
cFlatRadioUnCheck = 3;
cFlatRadioChecked = 4;

var
  fPemakai: TfPemakai;
  P_Acc_treenode:TTreenode;
  P_acc_structure:Array of TStructure;

implementation
uses uMainMenu;
{$R *.dfm}
procedure TfPemakai.FormCreate(Sender: TObject);
Begin
  with TreeView1 do
     begin
     FullExpand;
     Select(Items[0]);
    End;
end; 

procedure ToggleTreeViewCheckBoxes(Node:TTreeNode; cUnChecked, cChecked, cRadioUnchecked, cRadioChecked:integer);
var
  tmp:TTreeNode;
begin
  if Assigned(Node) then
  begin
    if Node.StateIndex = cUnChecked then
      Node.StateIndex := cChecked
    else if Node.StateIndex = cChecked then
      Node.StateIndex := cUnChecked
    else if Node.StateIndex = cRadioUnChecked then
    begin
      tmp := Node.Parent;
      if not Assigned(tmp) then 
        tmp := TTreeView(Node.TreeView).Items.getFirstNode
      else
        tmp := tmp.getFirstChild;
      while Assigned(tmp) do
      begin
        if (tmp.StateIndex in [cRadioUnChecked,cRadioChecked]) then
          tmp.StateIndex := cRadioUnChecked;
        tmp := tmp.getNextSibling;
      end;
      Node.StateIndex := cRadioChecked;
    end; 
  end; 
end; 
procedure TfPemakai.TreeView1Click(Sender: TObject);
var
  BoolResult:boolean;
begin
  GetCursorPos(P);
  P := TreeView1.ScreenToClient(P);
  if (htOnStateIcon in TreeView1.GetHitTestInfoAt(P.X,P.Y)) then
    ToggleTreeViewCheckBoxes(
       TreeView1.Selected,
       cFlatUnCheck,
       cFlatChecked,
       cFlatRadioUnCheck,
       cFlatRadioChecked);
if Assigned(TreeView1.Selected) then
  begin
    tn := TreeView1.Selected;
    BoolResult := tn.StateIndex in [cFlatChecked,cFlatRadioChecked];
    Memo1.Text := tn.Text +#13#10+ 'Selected: ' + BoolToStr(BoolResult, True);
   end;
end;
procedure TfPemakai.TreeView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_SPACE) and Assigned(TreeView1.Selected) then
    ToggleTreeViewCheckBoxes(TreeView1.Selected,cFlatUnCheck,cFlatChecked,cFlatRadioUnCheck,cFlatRadioChecked);
end; 

procedure TfPemakai.TreeView1Collapsing(Sender: TObject; Node: TTreeNode;
  var AllowCollapse: Boolean);
begin
  AllowCollapse := false;
end; 
procedure TfPemakai.btnTutupClick(Sender: TObject);
var Action: TCloseAction;
begin
close;
end;
procedure TfPemakai.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
Action:=caFree;
end;

//utk memberisihkan check box di treeview yg sudah di klik
//masih salah dan mohon bantuan rekan-rekan
procedure TfPemakai.btnbersihClick(Sender: TObject);
var 
    BoolResult:boolean;
J:Int;
begin
 J:=2;
         While J <= TreeView1.Items.Count do
         begin
             with TreeView1 do
             begin
             FullExpand;
             Select(Items[0]);
             TreeView1.ClearSelection(true);
             ActiveControl:= TreeView1;
             tn := TreeView1.Selected;
             tn.StateIndex :=1;
             End;
end;
end.
terima kasih.
user image
more 13 years ago

onsir

susah .. oyy
user image
more 13 years ago

cyber_hecker

treeview ku kok gak bisa pake checkbox ? gimana mbikinnya nih ?
user image
more 13 years ago

onsir

dapet dari alamat ini, mau nanya ke dia langsung gak bisa bahasanya. http://delphi.about.com/od/vclusing/l/aa092104a.htm
user image
more 13 years ago

cyber_hecker

udah ketemu.. udah ketemu.. wekekeke... :D
var
  i: integer;
begin
  for i := 0 to TreeView1.Items.Count - 1 do begin
    if TreeView1.Items[i].StateIndex = 2 then
      TreeView1.Items[i].StateIndex := 1;
  end;
user image
more 13 years ago

onsir

oke om cyber dah bisa. hebaaaat ente. ane dah ber hari-hari gak ketemu.
user image
more 13 years ago

onsir

misal sudah ada user A dengan akses kode=2121112 dan di simpan dlm tabel. lalu waktu kita edit user A tsb, secara otomatis akan mencentang chekbox sesuai dgn angka-angka tsb misal klw 2 maka akan terchekbox klw 1 tidak. terima kasih.
user image
more 13 years ago

cyber_hecker

cobain aja deh ...
{ for   : memberi tanda check sesuai kode sCheck, tapi hanya untuk
          child. untuk parent (StateIndex = -1) tidak. hitung child dgn benar
          atau akan error
  para  : -
  result: -
  -----------------------------------------------------------------------------}
procedure TForm1.Button2Click(Sender: TObject);
const
  sCheck = '1212121';
var
  i, n :integer;
begin
  n := 1;
  for i := 0 to TreeView1.Items.Count - 1 do begin
    if TreeView1.Items[i].StateIndex <> - 1 then begin
      TreeView1.Items[i].StateIndex := StrToInt(sCheck[n]);
      Inc(n);
    end;
  end;
end;
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com