5 Replies - 852 Views - Last Post: 18 June 2014 - 05:17 AM Rate Topic: -----

#1 xaxoto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-June 14

hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 17 June 2014 - 04:18 AM

hi how to make the transfer from ListBox1 in ListBox2 items without recurring transfer
example:
ListBox1.Items.add("a")
ListBox1.Items.add("b")
ListBox1.Items.add("b")
ListBox1.Items.add("c")
how to transfer them so that they remain only
ListBox2.Items.Item(0) = "a"
ListBox2.Items.Item(1) = "b"
ListBox2.Items.Item(2) = "c" ?

I used this code but when I redo the program only transfers all

 
For a = 0 To ListBox1.Items.Count - 1 '
            If ListBox1.FindString(ListBox1.Items.Item(a)) = -1 Then
                MsgBox("no")
            Else
                ListBox3.Items.Add(ListBox1.Items.Item(ListBox1.FindString(ListBox1.Items.Item(a))))
                    End If
           
        Next


thanks for your help in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: hi how to make the transfer from lb1 in lb2 item without recurring tra

#2 Charles:)  Icon User is offline

  • D.I.C Regular

Reputation: 149
  • View blog
  • Posts: 359
  • Joined: 26-November 09

Re: hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 17 June 2014 - 05:33 AM

Instead of working directly with the list box, you could create a class to store the items, and then use that class to populate list boxes. In your class you could store items in a HashSet<T> which automatically prevents you from adding duplicates.
Was This Post Helpful? 0
  • +
  • -

#3 xaxoto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-June 14

Re: hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 17 June 2014 - 06:11 AM

There is a small problem that ListBox1 loads it by mysql customer table and there I could not find how to filter table before loading it in ListBox1, about trying to transfer ListBox1 to ListBox2 without repeating
Was This Post Helpful? 0
  • +
  • -

#4 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 17 June 2014 - 09:12 AM

The best option that has been put to you is on post 2. See This Link for example.

Either alter your select statement and select only the values you need. Or in your return result - add the result to a list and iterate through that list to remove the values you dont want to keep, that is if you know what they are. Prevention is better than cure. Once you get that far, you will need to iterate through each item in listbox one and simply add it to listbox two.
Was This Post Helpful? 0
  • +
  • -

#5 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 143
  • Joined: 21-January 12

Re: hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 17 June 2014 - 09:43 PM

hi xaxoto, i have same problem a few days ago, but i use datagridview not listbox, i think it has same logic, see here : My link

here is the clue :

'declare a variable as string and asign it as empty string or ""
'create a loop for listbox1
'check if your variable that you declare before has the same value or not with your listbox1 items
       'if not, set your variable value to listbox1 item that has a same value
       'add your variable to listbox2 
'end if


Was This Post Helpful? 0
  • +
  • -

#6 Charles:)  Icon User is offline

  • D.I.C Regular

Reputation: 149
  • View blog
  • Posts: 359
  • Joined: 26-November 09

Re: hi how to make the transfer from lb1 in lb2 item without recurring tra

Posted 18 June 2014 - 05:17 AM

I strongly recommend not taking that approach. Controls should be purely about displaying information to the user, and receiving user input. All of your logic to do with processing and manipulating that information should be in your own custom classes.

If you use controls, rather than custom classes, to store and process your data, then you're going to end up with software that's very hard to maintain and resistant to change.

Do some research on MVVM and try to use that instead: http://en.wikipedia...._View_ViewModel
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1