ListView如何把某列所有数值相加列A
123
456
555如何把该列所有数值相加赋给Label1

解决方案 »

  1.   

    另外如何统计ListView里有多少行数据?
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        i, nSum: integer;
        nColIndex: integer;
    begin
        nSum := 0;
        nColIndex := 1; // 假设读取ListView的第2列    for i := 0 to ListView1.Items.Count - 1 do
        begin
            if nColIndex <= 0 then
                nSum := nSum + StrToIntDef(ListView1.Items[i].Caption, 0)
            else if nColIndex <= ListView1.Items[i].SubItems.Count then
                nSum := nSum + StrToIntDef(ListView1.Items[i].SubItems.Strings[nColIndex - 1], 0);
        end;    Label1.Caption := IntToStr(nSum);
    end;
      

  3.   

    void TForm1:Button1Click(Sender: TObject
    {
        int i, nSum,nColIndex;    nSum = 0;
        nColIndex = 1; // 假设读取ListView的第2列    for( i = 0;i< ListView1.Items.Count ;i++)
        { 
            if( nColIndex <= 0)
                nSum = nSum + StrToIntDef(ListView1->Items[i]->Caption, 0)
            else 
                nSum = nSum + StrToIntDef(ListView1.Items[i]->SubItems->Strings[nColIndex - 1], 0);
        }    Label1.Caption = IntToStr(nSum);
    }