请问:我在程序中需要判断是否选择了listbox中的项,如果选择做个动作,如果未选择做另外一个动作!比如:listbox1.items[0]:=0,…listbox1.items[10]:=9;
如果已经选中某项,则索引指向下一项,否则提示未选择项(不要重复提示)!

解决方案 »

  1.   

    if listbox2.itemindex<>-1 then
          begin
          if listbox2.ItemIndex<listbox2.Items.Count-1 then
             listbox2.Items.Move(listbox2.ItemIndex,listbox2.ItemIndex+1);
          if listbox2.ItemIndex=listbox2.Items.Count-1 then
      

  2.   

    用了index了,可是总是说(-1)错误!!郁闷呢!帮忙写一个啊,我正在排除异常呢
      

  3.   

    begin
        if listbox2.itemindex<>-1 then
          begin
            if listbox2.ItemIndex<listbox2.Items.Count-1 then
             listbox2.Items.Move(listbox2.ItemIndex,listbox2.ItemIndex+1);
            if listbox2.ItemIndex=listbox2.Items.Count-1 then
               begin
                 showmessage('已经最下,不能下移了');
                 exit;
               end;
        end
        else
              showmessage('无选择项');
      edit1.text:=inttostr(listbox2.itemindex);
      edit2.Text:=inttostr(listbox2.Items.count-1);
    end;
    解决了,谢谢2楼的回复,给分