Combo Box disable manual entry

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
lcrltd
Junior Coder
Posts: 35
Joined: Thu Nov 16, 2006 8:23 am

Combo Box disable manual entry

Post by lcrltd » Thu Aug 04, 2011 12:26 pm

Is there a way to disable being able to type any value into a combo box, in other words restrict it to only the items I tell it to?

At the moment , if I have Item1 item2 item3 in the drop down, I can type UYIUYIUY or anything in the box.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Aug 04, 2011 2:48 pm

Set the ComboBox style to either csOwnerDrawFixed or csDropDownList

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 111
  ClientWidth = 208
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSComboBox1: tMSComboBox
    Left = 15
    Top = 7
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 0
    Items.Strings = (
      'Option 1'
      'Option 2'
      'Option 3'
      'Option 4'
      'Option 5'
      'Option 6')
    ListText = 'Option 1'#13#10'Option 2'#13#10'Option 3'#13#10'Option 4'#13#10'Option 5'#13#10'Option 6'#13#10
  end
  object MSComboBox2: tMSComboBox
    Left = 16
    Top = 48
    Width = 145
    Height = 19
    Style = csOwnerDrawFixed
    ItemHeight = 13
    TabOrder = 9
    Items.Strings = (
      'Option 1'
      'Option 2'
      'Option 3'
      'Option 4'
      'Option 5'
      'Option 6')
    ListText = 'Option 1'#13#10'Option 2'#13#10'Option 3'#13#10'Option 4'#13#10'Option 5'#13#10'Option 6'#13#10
  end
end
EndDialog>Dialog1


Show>Dialog1,r

lcrltd
Junior Coder
Posts: 35
Joined: Thu Nov 16, 2006 8:23 am

Post by lcrltd » Thu Aug 04, 2011 3:11 pm

Thank you ! Works a treat.

Is there any way to get a drop box to automatically go to another field, for example if I select from a drop down a name, for it to then set focus on another edit field?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Aug 04, 2011 4:31 pm

This will focus edit1 when you select a ComboBox Option.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 659
  Top = 121
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 111
  ClientWidth = 208
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSComboBox1: tMSComboBox
    Left = 15
    Top = 7
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    TabOrder = 0
    Items.Strings = (
      'Option 1'
      'Option 2'
      'Option 3'
      'Option 4'
      'Option 5'
      'Option 6')
    ListText = 'Option 1'#13#10'Option 2'#13#10'Option 3'#13#10'Option 4'#13#10'Option 5'#13#10'Option 6'#13#10
  end
  object Edit1: TEdit
    Left = 16
    Top = 40
    Width = 145
    Height = 21
    TabOrder = 9
    Text = 'Edit1'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSComboBox1,OnSelect,FocusEdit1

Show>Dialog1,r


SRT>FocusEdit1
  SetDialogObjectFocus>Dialog1,Edit1
END>FocusEdit1

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts