procedure TForm9.StringGrid1Click(Sender: TObject);
var i,j:integer;
    rect:TRect;
    str:string;
begin
  for i:=1 to stringgrid1.RowCount do
     begin
          stringgrid1.Cells[0,i]:='';
         for j:=1 to 6 do
           begin
            str:=stringgrid1.Cells[j,i];
            stringgrid1.Canvas.Brush.Color:=clwhite;
            rect:=stringgrid1.CellRect(j,i);
            stringgrid1.Canvas.FillRect(rect);
            stringgrid1.Canvas.Font.Color:=cldefault;
            stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);
           end;
       end;
    stringgrid1.Cells[0,stringgrid1.Row]:='->';
  for i:=1 to 6 do
    begin
    str:=stringgrid1.Cells[i,stringgrid1.Row];
    stringgrid1.Canvas.Brush.Color:=cllime;
    rect:=stringgrid1.CellRect(i,stringgrid1.Row);
    stringgrid1.Canvas.FillRect(rect);
    stringgrid1.Canvas.Font.Color:=cldefault;
    stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);
    end;
  //  showmessage(stringgrid1.Cells[1,stringgrid1.Row]);
end;

解决方案 »

  1.   

    点击dbgrid时根据dbgrid中的唯一值字段去查找stringgrid中的值
    例: dbgrid第一列对应query1中的字段'dd'
    在dbgridclick事件中写如下:
    for j:=1 to 6 do
               begin
                str:=stringgrid1.Cells[j,i];
                stringgrid1.Canvas.Brush.Color:=clwhite;
                rect:=stringgrid1.CellRect(j,i);
                stringgrid1.Canvas.FillRect(rect);
                stringgrid1.Canvas.Font.Color:=cldefault;
                stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);
               end;
           
     for i:=0 to stringgrid.rows do
     begin
       if stringgrid.cells[0,i]=query1.fieldbyanme('dd').asstring then
         begin
          for i:=1 to 6 do
        begin
        str:=stringgrid1.Cells[i,stringgrid1.Row];
        stringgrid1.Canvas.Brush.Color:=cllime;
        rect:=stringgrid1.CellRect(i,stringgrid1.Row);
        stringgrid1.Canvas.FillRect(rect);
        stringgrid1.Canvas.Font.Color:=cldefault;
        stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);
        end;
      end;
      

  2.   

    老兄:
      我是单击dbgrid使得stringgrid的某行加亮显示啊
      

  3.   

    应该还要加几句
    for i:=1 to stringgrid1.rowcount do
    begin
       if stringgrid1.cells[0,i]=Query1.fieldbyname('dd').asstring then
           begin
             k:=i;
             break;
           end;
    end;
    for i:=1 to k do
    begin
    for j:=1 to 6 do
       begin
       str:=stringgrid1.Cells[j,i];
       stringgrid1.Canvas.Brush.Color:=clwhite;
       rect:=stringgrid1.CellRect(j,i);
       stringgrid1.Canvas.FillRect(rect);
       stringgrid1.Canvas.Font.Color:=cldefault;
       stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);
       end;
      end;    
     for i:=1 to 6 do //6为stringgrid1的列数
        begin
        str:=stringgrid1.Cells[i,k];
        stringgrid1.Canvas.Brush.Color:=cllime;
        rect:=stringgrid1.CellRect(i,k);
        stringgrid1.Canvas.FillRect(rect);
        stringgrid1.Canvas.Font.Color:=cldefault;
        stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,str);  end;