Drop Downs relationship

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Drop Downs relationship

Post by Identis » Fri Mar 27, 2015 2:46 pm

Hello,

I have question about DropDown relationship with other dropdown. How I can do that in "Subcategory" dropdown values will change depends on what Category is selected ?

Here is my dialog example:
I need for every category selected, different subcategory list will be shown.
Waiting for help :)


Dialog>Dialog1
object Dialog1: TForm
Left = 247
Top = 97
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 211
ClientWidth = 431
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 Category: tMSComboBox
Left = 25
Top = 27
Width = 145
Height = 21
ItemHeight = 13
TabOrder = 8
Text = 'Category'
end
object Subcategory: tMSComboBox
Left = 210
Top = 27
Width = 145
Height = 21
ItemHeight = 13
TabOrder = 9
Text = 'Subcategory'
end
object comment: TEdit
Left = 58
Top = 67
Width = 279
Height = 62
TabOrder = 10
Text = 'comment'
end
object ok: tMSButton
Left = 90
Top = 146
Width = 75
Height = 25
Caption = 'ok'
DoubleBuffered = True
ParentDoubleBuffered = False
TabOrder = 11
DoBrowse = False
BrowseStyle = fbOpen
end
object cancel: tMSButton
Left = 230
Top = 145
Width = 75
Height = 25
Caption = 'cancel'
DoubleBuffered = True
ParentDoubleBuffered = False
TabOrder = 12
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
Show>dialog1,r

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Drop Downs relationship

Post by JRL » Fri Mar 27, 2015 7:01 pm

Here's one way it could be done. See the comments.


Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 553
  Top = 202
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 211
  ClientWidth = 431
  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 Label1: TLabel
    Left = 72
    Top = 8
    Width = 42
    Height = 13
    Caption = 'Category'
  end
  object Label2: TLabel
    Left = 248
    Top = 8
    Width = 60
    Height = 13
    Caption = 'Subcategory'
  end
  object Category: tMSComboBox
    Left = 25
    Top = 27
    Width = 145
    Height = 21
    TabOrder = 0
    Items.Strings = (
      'Fruit'
      'Vegetables'
      'Dairy')
    ListText = 'Fruit'#13#10'Vegetables'#13#10'Dairy'#13#10
  end
  object Subcategory: tMSComboBox
    Left = 210
    Top = 27
    Width = 145
    Height = 21
    TabOrder = 1
  end
  object comment: TEdit
    Left = 58
    Top = 67
    Width = 279
    Height = 21
    TabOrder = 2
    Text = 'comment'
  end
  object ok: tMSButton
    Left = 90
    Top = 146
    Width = 75
    Height = 25
    Caption = 'ok'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object cancel: tMSButton
    Left = 230
    Top = 145
    Width = 75
    Height = 25
    Caption = 'cancel'
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

//Handlers for the ComboBoxes.  When the value is changed
//jump to the specified subroutine.
AddDialogHandler>Dialog1,Category,OnChange,ChangeSubCategory
AddDialogHandler>Dialog1,SubCategory,OnChange,ReadSubCategory

//A simple way to specify a list.
LabelToVar>FruitList,FList
LabelToVar>VegetableList,VList
LabelToVar>DairyList,DList

Show>dialog1,r


SRT>ChangeSubCategory
  //Get the Category selection
  GetDialogProperty>Dialog1,Category,Text,vText
  //Set the previous subcategory selection to blank.
  SetDialogProperty>Dialog1,SubCategory,Text,
  //Set the subcategory list to the category selection
  If>vText=Fruit
     SetDialogProperty>Dialog1,SubCategory,ListText,FList
  EndIF
  If>vText=Vegetables
     SetDialogProperty>Dialog1,SubCategory,ListText,VList
  EndIF
  If>vText=Dairy
     SetDialogProperty>Dialog1,SubCategory,ListText,DList
  EndIF
END>ChangeSubCategory

SRT>ReadSubCategory
  GetDialogProperty>Dialog1,SubCategory,Text,vSubText
  SetDialogProperty>Dialog1,Comment,Text,vSubText
END>ReadSubCategory


/*
FruitList:
Apple
Pear
Orange
Banana
*/

/*
VegetableList:
lettuce
cauliflour
peas
carrots
*/

/*
DairyList:
Milk
Cheese
Eggs
Yogurt
*/

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Drop Downs relationship

Post by Identis » Fri Mar 27, 2015 7:16 pm

Thank you very much :)

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