我的stringgrid内容假设如下
选择否     单号
            1
  Y         2
  Y         3
            4
  Y         5
            6   注:选Y的项不一定是连续行
我的“选择否”栏位是双击来打Y的,现在我如何判断是 “Y” 的第一行索引号及最后一行索引行号并分别用变量记录下来?
谢谢各位大虾了

解决方案 »

  1.   

    hvae a tryfor i := 0 to StringGrid1.Items.Count-1 do
    begin
      if StringGrid1.Items[i].Selected then
      begin
        //
      end;
    end;
      

  2.   

    to gzmhero(hihihi)你能稍微给个例子么?我就是没想通这个循环要怎么写?而且怎么判断哪行是最后一个出现Y的?
      

  3.   

    to qybao(阿宝)
    不明白这怎么用!!!
    我怎么没有StringGrid1.Items啊????
      

  4.   

    to qybao(阿宝)
    不明白这怎么用!!!
    我怎么没有StringGrid1.Items啊????-------
    你的StringGrid的Name不是StringGrid1吧,是什么就改成什么
      

  5.   

    for i:=0 to StringGrid1.RowCount-1 do
        if StringGrid1.Cells[0,i]='Y' then
         .................
      

  6.   

    楼上各位大虾,经人指点,终于知道我哪里想错了,解决了,也谢谢各位大虾出手了
    解决的思路:
    for i:=1 to StringGrid1.RowCount-1 do begin
        if StringGrid1.Cells[0,i]='Y' then begin 
    a:=i;
        if b=0 then b:=a ;
        end;
      end;
      

  7.   

    楼上各位大虾,经人指点,终于知道我哪里想错了,解决了,也谢谢各位大虾出手了
    解决的思路:
    for i:=1 to StringGrid1.RowCount-1 do begin
        if StringGrid1.Cells[0,i]='Y' then begin 
           a:=i;
           if b=0 then b:=a ; //这里当初没有判断if b=0 , 而是直接b:=a了,所以导致b一直被刷新
        end;
      end;