即:如何实现点击stringgrid 中的一个单元,
      如果是和该单元同一行的,让列值小于该单元列的所有单元变为同一种颜色;
      如果是和该单元同一列的,让行值小于该单元行的所有单元也变为这种颜色相当于这样 的效果
                   =
                   =
                   =
                   =   
 ==========

解决方案 »

  1.   

    var
        CurCol,CurRow:integer;procedure TForm1.StringGrid1Click(Sender: TObject);
    begin
        CurCol:=StringGrid1.Selection.left;
        CurRow:=StringGrid1.Selection.Top;
        StringGrid1.Refresh;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
        if ACol*ARow=0 then
            exit;
        if ((ACol<CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then
            ImageList1.Draw(StringGrid1.Canvas,Rect.Left,Rect.Top,2);
    end;
      

  2.   

    上面的代码是在选中的行、列上面画一个图标。
    下面的代码能够变色。
    var
      CurCol,CurRow:integer;
    procedure TForm1.Button1Click(Sender: TObject);
    var
        i,j:integer;
    begin
        StringGrid1.RowCount:=StrToInt(Edit1.Text);
        StringGrid1.ColCount:=StrToINt(Edit2.Text);
        for i:=0 to StrToInt(Edit1.Text) do
            for j:=0 to StrToInt(Edit2.Text) do
                StringGrid1.Cells[i,j]:=IntToStr(i*j);
    end;procedure TForm1.StringGrid1Click(Sender: TObject);
    begin
        CurCol:=StringGrid1.Selection.left;
        CurRow:=StringGrid1.Selection.Top;
        StringGrid1.Refresh;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
        if CurCol*CurRow*ACol*ARow=0 then
            exit;    if ((ACol<=CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then
        begin
            StringGrid1.Canvas.Brush.Color:=clBlue;
        end else
        begin
            StringGrid1.Canvas.Brush.Color:=clWindow;
        end;
        StringGrid1.Canvas.FillRect(Rect);
        StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ARow,ACol]);
    end;
      

  3.   

    ImageList1.Draw(StringGrid1.Canvas,Rect.Left,Rect.Top,2);
    楼上这句什么意思呀/
    我把HELP的代码COPY到程序中,没什么效果呀!
      

  4.   

    ImageList1.Draw(StringGrid1.Canvas,Rect.Left,Rect.Top,2);/////////////////
    这句是把ImageList1中的index为2的图画到StringGrid1的画布上,从位置Rect.Left,Rect.top开始画。
      

  5.   

    还需要借助 另外一个imagelist1 控件的?
      

  6.   

    CurCol:=StringGrid1.Selection.left;
     CurRow:=StringGrid1.Selection.Top;是怎么理解的呀 ,
     当前行 在所选中单元的最高
     当前列 在所选中单元的最左?