DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Deselect one item in listbox on Dialog Box by using Script

Solved!
Go to solution
Highlighted

Hello,

 

I have a ListBox with a couple of listitems on Dialog Box.

I have a script to select listitem for doing somthing. Could you please help how to deselect that selected listitem with script?

 

Regards,

Gman

 

0 Kudos
Message 1 of 5
(213 Views)

In this example SUD I have attached, I fill a listbox with some numbers on startup.  As soon as i make a selection, it deselects.  Basically, do:

ListBox.Selection = -1
0 Kudos
Message 2 of 5
(196 Views)

Hi gsklyr,

Thank you for your advice. 

It's my fault not to explain my question clearly.

The following is what I want to do:

1. Click one listitem to trigger a "ListBox1_EventChange" for doing something.

2. Deselect the selected listitem.

3. Repeat step1.2 (clicking same listitem).

 

Now the issue is I only can trigger "ListBox1_EventChange" once by clicking the same listitem before I click other listitems, even I reset Listbox1.selection to -1 as your suggestion.

 

By the way I cannot open your example.

 

Thanks,

Gman

0 Kudos
Message 3 of 5
(140 Views)
Solution
Accepted by topic author gq
'-------------------------------------------------------------------------------
'-- SUD script file
'-- Created on 10/08/2019 09:04:29
'-- Author: 
'-- Comment: 
'-------------------------------------------------------------------------------
Option Explicit  'Forces the explicit declaration of all the variables in a script.

'Note: In this area area you can program auxiliary variables and functions that you can use in the entire dialog box.

Sub ListBox1_EventInitialize(ByRef This) 'Created Event Handler
  Call ListBox1.Items.RemoveAll()
  Call ListBox1.Items.Add(" - 1 - ", 0)
  Call ListBox1.Items.Add(" - 2 - ", 1)
  Call ListBox1.Items.Add(" - 3 - ", 2)
  Call ListBox1.Items.Add(" - 4 - ", 3)
End Sub

Sub Button1_EventClick(ByRef This) 'Created Event Handler
  ListBox1.Value = -1
  ListBox1.Selection = -1
End Sub

Sub ListBox1_EventChange(ByRef This) 'Created Event Handler
  If ListBox1.Selection = -1 Then
    Call MsgBox("De-Select Event")
  Else
    Call MsgBox("Regular Event")
  End If
End Sub
 

 

Capture.JPGSUD

Instead of the button, you can have th last line of your event change be listbox1.selection = -1 to clear

 

Sorry the key is to clear the value as well... listbox.value = -1 (read your post more carefully)

0 Kudos
Message 4 of 5
(133 Views)

Hi gsklyr,

I'm really appreciated your response. It really help me.

Here is my lesson from practice:

These two commands,ListBox1.Value = -1
  ListBox1.Selection = -1, cannot be put inside "ListBox1_EventChange(ByRef This)".

 

Spoiler
Which can cause an infinite loop.

Thanks,
Gman

 

 


 

 

 

Message 5 of 5
(111 Views)