在ComboBox中怎么让他的个别选项变灰,即不可选?谢谢赐教!

解决方案 »

  1.   

    把 CommoBox.Style:=csOwnerDrawVariable或者csOwnerDrawFixed
    然后在ComboBox1DrawItem事件中做判断和绘图
    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      rt: TRect;
    begin
      with ComboBox1.Canvas do
      begin
        rt := Rect;
        Brush.Color := clBtnFace;
        FillRect(rt);
        //if 做判断哪个要变灰 then
          Font.Color := clGrayText;
        DrawText(Handle, PChar(ComboBox1.Items.Strings[0]),
          -1, rt, DT_CENTER or DT_VCENTER or DT_BOTTOM);
      end;
    end;
      

  2.   

    procedure TForm1.ComboBox1Click(Sender: TObject);
    begin
    if ComboBox1.ItemIndex=1 then ComboBox1.ItemIndex:=-1;
    end;