Solved

ComboBox csOwnerDrawVariable BUG?

Posted on 2004-04-05
3
600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to build JSON File in Delphi 6 3 94
How to Get Images From Server using App Tethering 11 52
Firemonkey BASS_Init into a thread 17 80
QuickReport, Delphi, Shape 12 47
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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