Hello Tim,

Monday, September 22, 2003, 8:29:15 AM, you wrote:

T> pada grid tersebut dgMultiSelect sudah saya aktifkan,
T> lTotal = label total pertama kali diisi default total seluruhnya. namun
T> jika user
T> memilih item barang yang dia suka maka lTotal juga berubah sesuai
T> dengan harga item barang tersebut.

T> Pertanyaan:
T> 1.  Gimana cara kalkulasi lTotal utk mengecheck item barang apa saja
T>     yang dia select (highlight) karena bisa lebih dari 1. (gak nemu
T>     didemo)

T> -------------
T> 2. bisa kah grid diberi garis pemisah (border) ? sehingga jika
T>     (discount > 0) = true maka diberi garis border di atas

1. coba pake ginian (dari www.scalabium.com)

{
If your users can select a rows in the DBGrid, then you must navigate
and process them. The TDBGrid component have a SelectedRows property, in which
stores a list with bookmarks on each selected record.
}

var i: Integer;
begin
  for i := 0 to yourMDBGrid.SelectedRows.Count-1 do
  begin
    yourMDBGrid.DataSource.DataSet.Bookmark := yourMDBGrid.SelectedRows[i];

    {here you can process a selected record.
     For example, to sum the Amount field values}
    Inc(intSumAmount, yourMDBGrid.DataSource.DataSet.FieldByName('Amount').AsFloat);
  end;
end;

*** atau ini (dari www.swissdelphicenter.com)

{
 In the "Object Inspector" set your DBGrid's Option for dgMultiSelect = True.
 The Grid_Edit function calls for each selected DBGrid-Row a data-processing
 function.
 Return value is the number of processed rows.
}

function TForm1.Grid_Edit(dbgIn: TDBGrid; qryIn: TQuery): Longint;
  // declared in the private section
  // als private deklariert
begin
  Result := 0;
  with dbgIn.DataSource.DataSet do
  begin
    First;
    DisableControls;
    try
      while not EOF do
      begin
        if (dbgIn.SelectedRows.CurrentRowSelected = True) then
        begin
          { +++ Call here the data-processing function +++

           zb. iValue := qryIn.FieldByName('FIELDNAME').AsInteger;
          }
          Inc(Result);
        end;
        Next;
      end;
    finally
      EnableControls;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form1.Caption := 'Processed: ' + IntToStr(Grid_Edit(DBGrid1, Query1));
end;

**** atau coba ini (dari www.delphi.about.com)

{
1. First use Object Inspector and set True to properties: dgMultiSelect and
   dgRowSelect. Note that when you set dgRowSelect to true, the dgEditing is
   automatically set to false.

2. Then, you can use the following function to sum, for example, values in the
   AField filed in all the rows selected (in the Table1, DBGrid1)!
}

function SUMSomething: Float;
var
 i: Integer;
 Sum: Currency;
begin
 Sum := 0;
 for i := 1 to DBGrid1.SelectedRows.Count do
  begin
   Table1.GotoBookMark
     (Pointer(DBGrid1.SelectedRows.Items[i-1]));
   {
    The TDBGrid component keeps all the selections as Bookmarks in a
    TStringList, and all the Bookmarks must be converted to a Pointer
    (what they really are) before using it.
   }
    Sum := Sum +
           Table1.FieldByName('AField').AsFloat;
  end;
 Result := Sum;
end;

*****

2.  Untuk bikin garis, kayaknya nggak bisa deh (CMIIW). kalo bikin
warna yang beda bisa. coba ini (dari www.swissdelphicenter.com)

// Function to color a DBGrid (declared as private)

procedure TForm1.ColorGrid(dbgIn: TDBGrid; qryIn: TQuery; const Rect: TRect;
  DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
  iValue: LongInt;
begin
  // color only the first field
  if (DataCol = 0) then
  begin
    // Check the field value and assign a color
    iValue := qryIn.FieldByName('HINWEIS_COLOR').AsInteger;
    case iValue of
      1: dbgIn.Canvas.Brush.Color := clGreen;
      2: dbgIn.Canvas.Brush.Color := clLime;
      3: dbgIn.Canvas.Brush.Color := clYellow;
      4: dbgIn.Canvas.Brush.Color := clRed;
    end;
    // Draw the field
    dbgIn.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  ColorGrid(DBGrid1, Query1, Rect, DataCol, Column, State);
end;

****

semoga membantu :)

-- 
Best regards,
 Irwan
 [EMAIL PROTECTED]

NB: Download aja Tips Explorer dari files section-nya delphindo. ada +3100 delphi
tips dari berbagai website



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Upgrade to 128-Bit SSL Security!
http://us.click.yahoo.com/p7cEmB/s7qGAA/yigFAA/i7folB/TM
---------------------------------------------------------------------~->

Berlangganan: [EMAIL PROTECTED]
Stop Berlangganan: [EMAIL PROTECTED]
Keluhan Milis(Unbouncing,spam,dll): [EMAIL PROTECTED] 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


Kirim email ke