Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi
My listbox should always have at least the first entry and another one selected. I have written a macro but it is not really doing anything (but it gets triggered). Found it also a bit difficult to find information how to manipulate qlik objects :-), the API Guide does not contain examples.
Sub include_first()
' always include first element in selection
Set oLB_Cat = ActiveDocument.GetSheetObject("CAT")
Set oCell = oLB_Cat.GetCell(1,0)
oCell.State = 5
msgbox("Cell.State: " & oCell.State)
' if first element only is selected, select second too
If oLB_Cat.GetRowCount = 1 Then
Set oCell = oLB_Cat.GetCell(2,0)
oCell.State = 5
End If
End Sub
Thanks for your help, Juerg
I hope I understand what you're going for.
I set up a dummy app and gave it one field. I then set up a Trigger to fire on any Selection in that field. The macro will select the first value if it is not already selected, while keeping any other selections. Also, if the only thing selected if the first value, it also selects the second value. Here's the Sub:
Sub SelectFirst
set sel = ActiveDocument.Fields("Selections")
Set oLB_Cat = ActiveDocument.GetSheetObject("LB01")
Set oCell = oLB_Cat.GetCell(0,0)
Set oCell2 = oLB_Cat.GetCell(1,0)
selected = ActiveDocument.Variables("vSelected").GetContent.String
' To keep current selections
' and select first
If Not InStr(selected, oCell.Text) Then
sel.ToggleSelect oCell.Text
End If
' Select first only
' sel.Select oCell.Text
If sel.GetSelectedValues.Count = 1 Then
sel.ToggleSelect oCell2.Text
End If
End Sub
I've also attached the sample app.
I hope I understand what you're going for.
I set up a dummy app and gave it one field. I then set up a Trigger to fire on any Selection in that field. The macro will select the first value if it is not already selected, while keeping any other selections. Also, if the only thing selected if the first value, it also selects the second value. Here's the Sub:
Sub SelectFirst
set sel = ActiveDocument.Fields("Selections")
Set oLB_Cat = ActiveDocument.GetSheetObject("LB01")
Set oCell = oLB_Cat.GetCell(0,0)
Set oCell2 = oLB_Cat.GetCell(1,0)
selected = ActiveDocument.Variables("vSelected").GetContent.String
' To keep current selections
' and select first
If Not InStr(selected, oCell.Text) Then
sel.ToggleSelect oCell.Text
End If
' Select first only
' sel.Select oCell.Text
If sel.GetSelectedValues.Count = 1 Then
sel.ToggleSelect oCell2.Text
End If
End Sub
I've also attached the sample app.