怎样让listbox上的项全都成为被选中的状态(listbox已设为允许多选)

解决方案 »

  1.   

    yes listbox1.selectall;或者使用循环来设置所有项为selected;
      

  2.   

    ListBox1.Selected[1]:=true;
       ListBox1.Selected[2]:=true;
      

  3.   

    procedure TForm1.Button4Click(Sender: TObject);
    begin
      ListBox1.SelectAll;
      ListBox1.Selected[5]:=false;
    end;
      

  4.   

    再问一个难点的:
    怎样给listbox的某一项设为不同颜色?能做到这样的功能吗?
      

  5.   

    //参考如下代码~~
    (*
    object ListBox1: TListBox
      Style = lbOwnerDrawFixed
      OnDrawItem = ListBox1DrawItem
    end
    *)type
      TListBoxEx = class(TListBox);procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
      TListBoxEx(Control).OnDrawItem := nil;
      try
        if Odd(Index) then
          TListBoxEx(Control).Canvas.Brush.Color := $C0DCC0
        else TListBoxEx(Control).Canvas.Brush.Color := $0000C0;
        TListBoxEx(Control).DrawItem(Index, Rect, State);
      finally
        TListBoxEx(Control).OnDrawItem := ListBox1DrawItem;
      end;
    end;
      

  6.   

    ListBox1.SelectAll;
    ListBox1.Selected[1] := True;
    ListBox1.Selected[2] := False;