Clear ComboBox when Style=csDropDownList

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Clear ComboBox when Style=csDropDownList

Post by Dominic_Fichera » Tue Jan 26, 2016 11:22 pm

Hey guys,

Does anyone have a suggestion for how to clear a ComboBox when the Style=csDropDownList?

I've tried:

1) The regular: SetDialogProperty>Dialog,ComboBox,Text,
2) Setting one of the "ListText" values as a space (" ") and then SetDialogProperty>Dialog,ComboBox,Text,
3) SetDialogProperty>Dialog,ComboBox,Text,NULLCHAR

And no luck on any of them.

I essentially have a form which writes to a csv file, and once users click "save", it needs to clear for next use.

As always, thanks in advance,

Dominic Fichera

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

Re: Clear ComboBox when Style=csDropDownList

Post by JRL » Wed Jan 27, 2016 3:04 am

I'm not sure if this is what you're asking but I think this sample does what you want to happen. The chosen info in the combo box field resets when you set the combo box "listtext" property. This particular sample resets the listtext property to a new value but you could just keep setting it to the same list. I believe that will give you what you want.

SetDialogProperty>Dialog1,MSListBox1,Text,NewLList

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 350
  Top = 155
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 223
  ClientWidth = 340
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 14
    Top = 30
    Width = 121
    Height = 21
    TabOrder = 0
  end
  object Edit2: TEdit
    Left = 177
    Top = 30
    Width = 121
    Height = 21
    TabOrder = 5
  end
  object MSListBox1: tMSListBox
    Left = 14
    Top = 110
    Width = 121
    Height = 97
    ItemHeight = 13
    Items.Strings = (
      'item1'
      'item2'
      'item3')
    TabOrder = 1
    Text = 'item1'#13#10'item2'#13#10'item3'#13#10
    SelectedIndex = -1
  end
  object MSComboBox1: tMSComboBox
    Left = 177
    Top = 110
    Width = 145
    Height = 21
    Style = csDropDownList
    TabOrder = 2
    Items.Strings = (
      'item1'
      'item2'
      'item3')
    ListText = 'item1'#13#10'item2'#13#10'item3'#13#10
  end
  object MSButton1: tMSButton
    Left = 14
    Top = 72
    Width = 51
    Height = 25
    Caption = 'Update'
    Enabled = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 86
    Top = 72
    Width = 49
    Height = 25
    Caption = 'Add'
    Enabled = False
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 177
    Top = 72
    Width = 48
    Height = 25
    Caption = 'Update'
    Enabled = False
    TabOrder = 6
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton4: tMSButton
    Left = 241
    Top = 72
    Width = 48
    Height = 25
    Caption = 'Add'
    Enabled = False
    TabOrder = 7
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1


AddDialogHandler>Dialog1,MSListBox1,OnClick,ListBoxEdit
AddDialogHandler>Dialog1,MSComboBox1,OnClick,CboxEdit
AddDialogHandler>Dialog1,MSButton1,OnClick,UpdateLB
AddDialogHandler>Dialog1,MSButton2,OnClick,AddLB
AddDialogHandler>Dialog1,MSButton3,OnClick,UpdateCB
AddDialogHandler>Dialog1,MSButton4,OnClick,AddCB
AddDialogHandler>Dialog1,Edit1,OnChange,TurnOnLAdd
AddDialogHandler>Dialog1,Edit2,OnChange,TurnOnCAdd
GetDialogProperty>Dialog1,MSListBox1,Text,CurLList
GetDialogProperty>Dialog1,MSComboBox1,ListText,CurCList

Show>Dialog1,

SRT>ListBoxEdit
  GetDialogProperty>Dialog1,MSListBox1,SelectedItems,CurText
  GetDialogProperty>Dialog1,MSListBox1,SelectedIndex,CurLSelection
  GetDialogProperty>Dialog1,MSListBox1,Text,CurLList
  Add>CurLSelection,1
  Separate>CurLList,crlf,LLine
  SetDialogProperty>Dialog1,Edit1,Text,CurText
  SetDialogProperty>Dialog1,MSButton1,Enabled,True
  SetDialogProperty>Dialog1,MSButton2,Enabled,True
END>ListBoxEdit


SRT>CboxEdit
  GetDialogProperty>Dialog1,MSComboBox1,ItemIndex,CurCSelection
  GetDialogProperty>Dialog1,MSComboBox1,ListText,CurCList
  Add>CurCSelection,1
  Separate>CurCList,crlf,CLine
  SetDialogProperty>Dialog1,Edit2,Text,CLine_%CurCSelection%
  SetDialogProperty>Dialog1,MSButton3,Enabled,True
  SetDialogProperty>Dialog1,MSButton4,Enabled,True
END>CboxEdit

SRT>UpdateLB
  GetDialogProperty>Dialog1,Edit1,Text,NewLText
  Let>NewLList=
  Let>LL=0
  Repeat>LL
    Add>LL,1
    If>LL=CurLSelection
      If>NewLText<>
        Concat>NewLList,%NewLText%%crlf%
      EndIf
    Else
      Let>Value=LLine_%LL%
      If>value<>
        Concat>NewLList,%value%%crlf%
      EndIf
    EndIf
  Until>LL=LLine_Count
  SetDialogProperty>Dialog1,MSListBox1,Text,NewLList
  SetDialogProperty>Dialog1,MSButton1,Enabled,False
  SetDialogProperty>Dialog1,MSButton2,Enabled,False
END>UpdateLB

SRT>AddLB
  GetDialogProperty>Dialog1,MSListBox1,Text,CurLList
  GetDialogProperty>Dialog1,Edit1,Text,NewLText
  Concat>CurLList,%NewLText%%crlf%
  SetDialogProperty>Dialog1,MSListBox1,Text,CurLList
  SetDialogProperty>Dialog1,MSButton1,Enabled,False
  SetDialogProperty>Dialog1,MSButton2,Enabled,False
END>AddLB

SRT>UpdateCB
  GetDialogProperty>Dialog1,Edit2,Text,NewCText
  Let>NewCList=
  Let>CC=0
  Repeat>CC
    Add>CC,1
    If>CC=CurCSelection
      If>NewCText<>
        Concat>NewCList,%NewCText%%crlf%
      EndIf
    Else
      Let>Value=CLine_%CC%
      If>value<>
        Concat>NewCList,%value%%crlf%
      EndIf
    EndIf
  Until>CC=CLine_Count
  SetDialogProperty>Dialog1,MSComboBox1,ListText,NewCList
  SetDialogProperty>Dialog1,MSButton3,Enabled,False
  SetDialogProperty>Dialog1,MSButton4,Enabled,False
END>UpdateCB

SRT>AddCB
  GetDialogProperty>Dialog1,MSComboBox1,ListText,CurCList
  GetDialogProperty>Dialog1,Edit2,Text,NewCText
  Concat>CurCList,%NewCText%%crlf%
  SetDialogProperty>Dialog1,MSComboBox1,ListText,CurCList
  SetDialogProperty>Dialog1,MSButton3,Enabled,False
  SetDialogProperty>Dialog1,MSButton4,Enabled,False
END>AddCB

SRT>TurnOnLAdd
  SetDialogProperty>Dialog1,MSButton2,Enabled,True
END>TurnOnLAdd

SRT>TurnOnCAdd
  SetDialogProperty>Dialog1,MSButton4,Enabled,True
END>TurnOnCAdd

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Clear ComboBox when Style=csDropDownList

Post by Dominic_Fichera » Wed Jan 27, 2016 4:17 am

That's perfect! Thanks JRL!

Still think it's a bit odd you can't clear the dropdown without resetting the list, but very glad it can be done at all. That makes life much easier!

Thanks again,

Dominic Fichera

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

Re: Clear ComboBox when Style=csDropDownList

Post by JRL » Wed Jan 27, 2016 4:30 am

Dominic,

Hope it helps.

Just realized I copied the wrong line from the script as the example line to make the combo box reset. The line that performs the magic is:

SetDialogProperty>Dialog1,MSComboBox1,ListText,CurCList

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Clear ComboBox when Style=csDropDownList

Post by Dominic_Fichera » Wed Jan 27, 2016 4:31 am

All good JRL :) I got the general idea with your explanation and have already modified my script accordingly.

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

Re: Clear ComboBox when Style=csDropDownList

Post by JRL » Wed Jan 27, 2016 4:58 am

Excellent! Glad you could see past my mistake.

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