2 Replies - 3064 Views - Last Post: 07 July 2010 - 04:24 AM Rate Topic: -----

#1 antovivek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 10

To store multiple selected values in a single field from listbox in vb

Posted 06 July 2010 - 12:56 AM

Hi This is vivek,

This is my code which i used to try this but it inserts only the last value in the listbox but i need all the selected values seperated by comma can any one help me




For i = 0 To ListBox1.SelectedItems.Count - 1
list = ListBox1.SelectedItems.Item(i) + ","
Next
Is This A Good Question/Topic? 0
  • +

Replies To: To store multiple selected values in a single field from listbox in vb

#2 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1374
  • View blog
  • Posts: 4,430
  • Joined: 25-September 09

Re: To store multiple selected values in a single field from listbox in vb

Posted 06 July 2010 - 04:16 AM

Two things I see, first, you need to append to list, otherwise you are just overwriting it and second you should really use & in VB.Net for appending try this:

For i = 0 To ListBox1.SelectedItems.Count - 1
list &= ListBox1.SelectedItems.Item(i) & ","
Next


the list &= is the same as using list = list & which is basically saying, whatever is in the list variable, save it and append to it.

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#3 antovivek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 10

Re: To store multiple selected values in a single field from listbox in vb

Posted 07 July 2010 - 04:24 AM

thank u charlie,
i got it its working now i have another problem.
im having a access table with sitename as a field which stores the value from listbox as u said. Now i need to load the other details in grid comparing the sitename.As while selecting the Sitename in combobox the corresponding other details such as name,id,salary,etc., have to be displayed. I dont know how to start can u help me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1