Solved

ComboBox csOwnerDrawVariable BUG?

Posted on 2004-04-05
3
569 Views
Last Modified: 2010-04-16
I have a combobox with csOwnerDrawVariable style. I need that when click a button and say ComboBox1.Text:='OK' to assign this string to combo text.
But this don't work. Look that don't work for an Owner style.

What to do to still have an owner drawing but to can assign a text to my combo ( Not just if I select one from drop list).
0
Comment
Question by:ginsonic
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
esoftbg earned 500 total points
ID: 10759982
All speed Buttons have Captions identical with Items of a ComboBox1 and call the method SpeedButton1Click:

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  I:      Integer;
  S:      string;
  T:      string;
begin
//  ComboBox1.Text := (Sender as TSpeedButton).Caption;  // doesn't work
  T := (Sender as TSpeedButton).Caption;
  with ComboBox1 do
  for I := 0 to Items.Count-1 do
  begin
    S := Items[I];
    if (S=T) then
    begin
      ItemIndex := I;
      Break;
    end;
  end;
end;

emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10763284
unit Unit_Q_20944122;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ToolWin, ComCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
  private  { Private declarations }
  public   { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  I:      Integer;
begin
//  ComboBox1.Text := (Sender as TSpeedButton).Caption;  // doesn't work
  with ComboBox1 do
  for I := 0 to Items.Count-1 do
  begin
    if (Items[I]=(Sender as TSpeedButton).Caption) then
    begin
      ItemIndex := I;
      Break;
    end;
  end;
  (Sender as TSpeedButton).Down := True;
end;

end.

//.............................................................

object Form1: TForm1
  Left = 199
  Top = 114
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 124
    Top = 50
    Width = 128
    Height = 22
    Style = csOwnerDrawVariable
    DropDownCount = 16
    ItemHeight = 16
    TabOrder = 0
    Items.Strings = (
      'Ok'
      'Cancel'
      'Yes'
      'No'
      'Don''t care'
      'Stop asking'
      'Start'
      'Stop')
  end
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 688
    Height = 29
    Caption = 'ToolBar1'
    TabOrder = 1
    object SpeedButton1: TSpeedButton
      Left = 0
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'Ok'
      OnClick = SpeedButton1Click
    end
    object SpeedButton2: TSpeedButton
      Left = 64
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'Cancel'
      OnClick = SpeedButton1Click
    end
    object SpeedButton3: TSpeedButton
      Left = 128
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'Yes'
      OnClick = SpeedButton1Click
    end
    object SpeedButton4: TSpeedButton
      Left = 192
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'No'
      OnClick = SpeedButton1Click
    end
    object SpeedButton5: TSpeedButton
      Left = 256
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'Start'
      OnClick = SpeedButton1Click
    end
    object SpeedButton6: TSpeedButton
      Left = 320
      Top = 2
      Width = 64
      Height = 22
      AllowAllUp = True
      GroupIndex = 1
      Caption = 'Stop'
      OnClick = SpeedButton1Click
    end
  end
end
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10763720
thats no bug,

with such a style the text-area is not editable.
you must add your text to the items and select the itemindex after this

like

procedure TForm1.Button1Click(Sender: TObject);
var idx : Integer;
begin
  idx := ComboBox1.Items.IndexOf('OK');
  if idx = -1 then
    idx := ComboBox1.Items.add('OK');
  ComboBox1.ItemIndex := idx;
end;

meikl ;-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question