如何删除ListBox中的某项内容?不用ListBox.Items.Delete();或者是ListBox.DeleteSelected;
我是要删除ListBox中指定其Items内容的那项,比如我要删除ListBox中的‘Beijng’,该怎么写?怎么获取Beijng’在ListBox中的ItemIndex值?

解决方案 »

  1.   

    var i:integer;
    begin
      i:=ListBox1.Items.IndexOf('Beijing');//获取ItemIndex
      ListBox1.Items.Delete(i);//删除
    end;
      

  2.   

    同意楼上的,但是最好加个判断,这样不会发生异常。
    var i:integer;
    begin
      i:=ListBox1.Items.IndexOf('Beijing');//获取ItemIndex
      if i <> -1 then
        ListBox1.Items.Delete(i);//删除
    end;
      

  3.   

    不需要判断的,看它的源码:
    procedure TCustomListBox.DeleteString( Index: Integer );
    begin
      SendMessage(Handle, LB_DELETESTRING, Index, 0);
    end;
    或者自己写一句:ListBox1.Items.Delete(-1);就知道了
      

  4.   

    var i:integer;
    begin
      i:=ListBox1.Items.IndexOf('Beijing');//获取ItemIndex
      ListBox1.Items.Delete(i);//删除
    end;