Solved

ComboBox csOwnerDrawVariable BUG?

Posted on 2004-04-05
3
550 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now