?
Solved

ComboBox csOwnerDrawVariable BUG?

Posted on 2004-04-05
3
Medium Priority
?
645 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 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