Highlight Value in ListBox based on variable value

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Jamball77
Newbie
Posts: 14
Joined: Tue Aug 11, 2015 2:25 pm

Highlight Value in ListBox based on variable value

Post by Jamball77 » Wed Sep 23, 2015 5:42 am

Hi, I'm trying to highlight values in a listbox
based on values i read in from a table using DBQuery.
array_Vars.jpg
The values are correct compared with the db table.

I then use SetDialogProperty to update the dialog with the variable values.

PROBLEM: only the Text boxes update. ListBoxes do not update. I need the correct ListBox value to be selected.

I believe the properties are correct because I can use GetDialogProperty to read the Dialog values I input by hand or select from the ListBoxes.

SetDialogProperty>Dialog1,Edit2,Text,CUDFS_1_1
SetDialogProperty>Dialog1,MSListBox1,SelectedItems,CUDFS_1_2
SetDialogProperty>Dialog1,MSListBox2,SelectedItems,CUDFS_1_6
SetDialogProperty>Dialog1,Edit3,Text,CUDFS_1_3
SetDialogProperty>Dialog1,MSListBox3,SelectedItems,CUDFS_1_4
SetDialogProperty>Dialog1,MSListBox4,SelectedItems,CUDFS_1_5

Here are the corresponding GetDialogProperty commands.

GetDialogProperty>Dialog1,Edit2,Text,QTY_N_TEST
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,TESTING_FINISH_COMP
GetDialogProperty>Dialog1,MSListBox2,SelectedItems,GR_RED_TAG
GetDialogProperty>Dialog1,Edit3,Text,REASONS
GetDialogProperty>Dialog1,MSListBox3,SelectedItems,HRS_RETEST
GetDialogProperty>Dialog1,MSListBox4,SelectedItems,HRS_REWORK

Many thanks in advance. James.
Last edited by Jamball77 on Wed Sep 23, 2015 12:47 pm, edited 2 times in total.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: SetDialogProperty from array via DBQuery

Post by hagchr » Wed Sep 23, 2015 7:51 am

Hi, not sure if you can use 'SelectedItems' that way. Until someone can help with that you can always use something like the SetList SRT below:

Code: Select all

Gosub>LoadDialog

Let>target1=Banana
Let>target2=Orange
Gosub>SetList,Dialog1,MSListBox1,target1
Gosub>SetList,Dialog1,MSListBox2,target2

Wait>3

SRT>SetList
    Let>LOCALVARS=1
    Let>tmpDialog=SetList_VAR_1
    Let>tmpObject=SetList_VAR_2
    Let>tmptarget=SetList_VAR_3
    LowerCase>tmptarget,tmptarget
    GetDialogProperty>tmpDialog,tmpObject,Text,tmplist
    Separate>tmplist,%CRLF%,tmplist

    Let>ct=0
    While>ct<tmplist_COUNT
        Add>ct,1
        LowerCase>tmplist_%ct%,tmplistval
        If>tmplistval=tmptarget
            Let>SelectedId=%ct%-1
        Endif
    EndWhile
    
    SetDialogProperty>tmpDialog,tmpObject,SelectedIndex,SelectedId
    Let>LOCALVARS=0
END>SetList

SRT>LoadDialog
    LabelToVar>Dialog,Dialog
    IncludeFromVar>Dialog
    Show>Dialog1
END>LoadDialog

/*
Dialog:
Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 290
  ClientWidth = 202
  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 MSListBox1: tMSListBox
    Left = 35
    Top = 17
    Width = 121
    Height = 64
    ItemHeight = 13
    Items.Strings = (
      'Apple'
      'Banana'
      'Tomato')
    TabOrder = 0
    Text = 'Apple'#13#10'Banana'#13#10'Tomato'#13#10
    SelectedIndex = -1
  end
  object MSListBox2: tMSListBox
    Left = 34
    Top = 114
    Width = 121
    Height = 97
    ItemHeight = 13
    Items.Strings = (
      'Green'
      'Yellow'
      'Blue'
      'Orange')
    TabOrder = 9
    Text = 'Green'#13#10'Yellow'#13#10'Blue'#13#10'Orange'#13#10
    SelectedIndex = -1
  end
end
EndDialog>Dialog1


*/

Jamball77
Newbie
Posts: 14
Joined: Tue Aug 11, 2015 2:25 pm

Re: SetDialogProperty from array via DBQuery

Post by Jamball77 » Wed Sep 23, 2015 12:43 pm

Thank you Hagchr!

That really helps and does exactly what I need, to highlight a value in listbox based on a variable. :D

As you pointed out it does seem to be an issue with SelectedItems since TEXT works just fine.

Such a pity, but makes sense that reading/writing a value is different from changing the format of an object.

With gratitude, James.

Jamball77
Newbie
Posts: 14
Joined: Tue Aug 11, 2015 2:25 pm

Re: Highlight Value in ListBox based on variable value

Post by Jamball77 » Thu Sep 24, 2015 2:22 pm

Followup:

A less elegant but easy fix is to put in a second "Current Values" text box to receive the array variables.

That gives me a field for current values and a second field (listbox) to push values into the database.

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