NAO PERMITIR REPETICAO

USUARIO.EXCLUIDOS 18/07/2005 20:33:26
#94805
Viva ppl !!!

tou com um problema em fazer com q na passagem de produtos da listview1 para a listview2, n seja possivel adicionar mais do q um produto do mesmo tipo ah listview2...

Sabem como posso resolver esse problema ?

cumps

USUARIO.EXCLUIDOS 18/07/2005 20:51:03
#94810
Resposta escolhida
cara... deixa eu pensar aki...
tá um teste completo.. fiz aki eu deu certinho... testa ae...

Private Sub Command1_Click()
Dim existe As Boolean
Dim item As Integer

item = List1.ListIndex
If item < 0 Then Beep: Exit Sub

For i = 0 To List2.ListCount - 1
If List2.List(i) = List1.List(item) Then existe = True
'Verifica se existe, e se existir anula a ação
Next
If existe Then Beep: Exit Sub

List2.AddItem List1.List(item)
List1.RemoveItem (item)

List2.ListIndex = List2.ListCount - 1 'dá o foco ao ultimo adicionado
If List1.ListCount > 0 Then List1.ListIndex = 0 'volta o foco pro list1
End Sub

Private Sub Command2_Click()
Dim existe As Boolean
Dim item As Integer

item = List2.ListIndex
If item < 0 Then Beep: Exit Sub

For i = 0 To List1.ListCount - 1
If List1.List(i) = List2.List(item) Then existe = True
'Verifica se existe, e se existir anula a ação
Next
If existe Then Beep: Exit Sub

List1.AddItem List2.List(item)
List2.RemoveItem (item)

List1.ListIndex = List1.ListCount - 1 'dá o foco ao ultimo adicionado
If List2.ListCount > 0 Then List2.ListIndex = 0 'volta o foco pro list1
End Sub

Private Sub Form_Load()
List1.AddItem "João"
List1.AddItem "Maria"
List1.AddItem "Paulo"
List1.AddItem "José"
End Sub
USUARIO.EXCLUIDOS 18/07/2005 21:12:29
#94816
obrigado...

vou experimentar e dps digo alguma coisa

USUARIO.EXCLUIDOS 18/07/2005 21:22:02
#94818
so ah um problema eh q em ListView n se pode usar as mesmas propriedades do q em List...

USUARIO.EXCLUIDOS 18/07/2005 21:27:04
#94819
eu para o primeiro command1 tentei mudar so q me tava dando erro ...

---------------------------------------------------------------------------------------------------
Dim Existe As Boolean
Dim Item As Integer

Item = ListView1.SelectedItem.Index
If Item < 0 Then Beep: Exit Sub

For i = 0 To ListView2.ListItems.Count - 1
If ListView1.ListItems(i) = ListView2.ListItems(Item) Then Existe = True

Next i
If Existe Then Beep: Exit Sub

ListView2.ListItems.Add ListView1.ListItems(Item) »Â» aqui ta dando erro
ListView1.ListItems.Remove (Item)

List2.ListIndex = ListView2.ListItems.Count - 1
If ListView1.ListItems.Count > 0 Then ListView1.ListItems.Clear

--------------------------------------------------------------------------------------------

cumps
USUARIO.EXCLUIDOS 18/07/2005 21:54:22
#94821
cara;;; ce caçou pedreira.. me fez até usar o maledito on error resume next


mas deve resolver...

Private Sub Command1_Click()
Dim Existe As Boolean
Dim Item As Integer

If ListView1.ListItems.Count = 0 Then Beep: Exit Sub
Item = ListView1.SelectedItem.Index
If Item < 0 Then Beep: Exit Sub

For i = 0 To ListView2.ListItems.Count - 1
If Eh_Item(ListView2, i) Then
If ListView2.ListItems(i) = ListView1.ListItems(Item) Then Existe = True
End If
Next i
If Existe Then Beep: Exit Sub

ListView2.ListItems.Add ListView2.ListItems.Count + 1, , ListView1.ListItems(Item) ' »Â» aqui ta dando erro
ListView1.ListItems.Remove (Item)
End Sub

Private Sub Command2_Click()
Dim Existe As Boolean
Dim Item As Integer

If ListView2.ListItems.Count = 0 Then Beep: Exit Sub
Item = ListView2.SelectedItem.Index
If Item < 0 Then Beep: Exit Sub

For i = 0 To ListView1.ListItems.Count - 1
If Eh_Item(ListView1, i) Then
If ListView1.ListItems(i) = ListView2.ListItems(Item) Then Existe = True
End If
Next i
If Existe Then Beep: Exit Sub

ListView1.ListItems.Add ListView1.ListItems.Count + 1, , ListView2.ListItems(Item) ' »Â» aqui ta dando erro
ListView2.ListItems.Remove (Item)
End Sub

Private Sub Form_Load()
ListView1.ListItems.Add ListView1.ListItems.Count + 1, , "Alisson"
ListView1.ListItems.Add ListView1.ListItems.Count + 1, , "Alisson 1"
End Sub

Function Eh_Item(destino As ListView, posicao) As Boolean
On Error Resume Next
valor = destino.ListItems(posicao)
If Err.Number > 0 Then
Eh_Item = False 'Não existe o bound
Else
Eh_Item = True
End If
End Function
USUARIO.EXCLUIDOS 18/07/2005 21:58:19
#94823
obrigado vou testar
USUARIO.EXCLUIDOS 18/07/2005 22:54:02
#94827
eu tive a tentar colocar a dica q voce me disse no meu programa, mas n esta sendo facil..

[S51]

If combo.Enabled = True Then
MsgBox "Seleccione o pagamento"
End If
Dim total As Integer
total = 0
Item = ListView1.SelectedItem
If Combo.Text = "Pagamento em Cheque" Then
Dim a As ListItem
Dim b As Integer
Set a = ListView2.ListItems.Add(, , Item)
a.SubItems(1) = "40"
b = (ListView2.ListItems.Count) * a.SubItems(1)
ListView1.ListItems.Remove Item ----------------------------» coloquei aqui esta linha
End If

Eu coloquei so aquela linha, porque queria q ao carregar no produto seleccionado, ele retira-se esse produto da listview1, uma vez q ja foi adicionado ah listview2.

eu tive a ver o seu exemplo, funciona perfeitamente mas tou com dificuldades em fazer o q pretendo :(

sera q me pode ajudar com base neste codigo ?

cumps
USUARIO.EXCLUIDOS 19/07/2005 18:51:10
#95060
cara altera a seguinte linha...
Item = ListView1.SelectedItem 

e conserta para
Item = ListView1.SelectedItem.Index


Tópico encerrado , respostas não são mais permitidas