Tenho uma aplicação onde existe um ComboBox, preciso que em determinada condição um item do Combobox seja apagado. fiz alguns testes criando um evento que ao ser verdadeiro removeria o item, no entanto ao rodar a aplicação gera um erro de Script (Argumento Inválido). Qual a forma correta de realizar tal comando?
Remover Itens do ComboBox
Qual tipo de argumento foi passado a função RemoveItem
? Ele deve ser o Index do item a ser removido, caso deseje remover por string
, sugiro algo como:
# combobox #
Sub ComboBox1_OnStartRunning()
AddItem "Hello"
AddItem "World"
End Sub
# e.g.: evento de 'click'
Sub btn_Click()
Dim cbo
Dim i
Dim sItem
Set cbo = Screen.Item("ComboBox1")
sItem = "hello"
For i = 0 To cbo.ListCount - 1
If (UCase( cbo.List(i) ) = UCase( sItem )) Then
cbo.RemoveItem( i )
Exit For
End If
Next
End Sub
Sub ComboBox1_OnStartRunning()
AddItem “Hello” ,0
AddItem “World” ,1
End Sub
Agora imagina uma condição, após esse evento executado “OnStarRunning” . se um bit for setado o item “Word”,1 seja retirado dessa combobox .
Obs: Não estou trabalhando com String, cada Índice esta vinculado a um inteiro.
Evento OnStarRunning
AddItem “Nenhum” , 0
AddItem “TQ 01” , 1
AddItem “TQ 02” , 2
AddItem “TQ 03” , 3
if Application.GetObject(“Dados.teste_Val”).Value = 0 then
ListIndex = 0
else if Application.GetObject(“Dados.teste_Val”).Value = 1 then
ListIndex = 1
else if Application.GetObject(“Dados.teste_Val”).Value = 2 then
ListIndex = 2
end if
end if
end if
Evento Click
If ListIndex = 0 then
Application.GetObject(“Dados.teste_Val”).Value = 0
else if ListIndex = 1 then
Application.GetObject(“Dados.teste_Val”).Value = 1
Else if ListIndex = 2 then
Application.GetObject(“Dados.teste_Val”).Value = 2
End if
end if
end if
Evento Atualizar
if Application.GetObject(“Dados.teste_Val”).Value = 0 then
ListIndex = 0
else if Application.GetObject(“Dados.teste_Val”).Value = 1 then
ListIndex = 1
else if Application.GetObject(“Dados.teste_Val”).Value = 2 then
ListIndex = 2
End if
end if
end if
Evento Remoção (Criado) ativo quando um determinado bit = true
RemoveItem “TQ 01” , 1
Bom, primeiramente penso que não seja necessário os If/Else
, seria apenas:
# on start running
Application.GetObject("Dados.teste_Val").Value = ListIndex
# ou, no click
ListIndex = Application.GetObject("Dados.teste_Val").Value
Quanto a remover um item pelo nome quando um bit
for a True
, entendo que existam mais de uma forma de fazer isso, uma delas seria associar o Value
deste Tag
a algum objeto da tela e no ChangeValue
criar uma função.
Sub OnChangeValue()
If ( bit ) Then
RemoveItemByName Screen.Item("ComboBox1"), "TQ 01"
End If
End Sub
Sub RemoveItemByName( objCombobox , strItem )
Dim i
For i = 0 To objCombobox.ListCount - 1
If (UCase( objCombobox.List(i) ) = UCase( strItem )) Then
objCombobox.RemoveItem( i )
Exit Sub
End If
Next
End Sub