473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem setting more than one selected value in a list box


Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to use
the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.
Nov 19 '05 #1
5 1980
ListBox.Items(0).Value = "Foo"
ListBox.Items(1).Value = "Foo1"

The number (0) is the ordinal reference of the list box item, zero based,
starting from the top.

Your code was actually setting the selected value, as would happen if the
user clicked the item on the list.

Hope that helps!

Simon.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...

Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to
use
the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.

Nov 19 '05 #2
allow multiple selection and set items as selected not selected value

listbox.Items[0].Selected=true; etc...

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...

Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to
use
the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.

Nov 19 '05 #3
Oops - Forget my answer, totally mis-read your post! Zzzz....

"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:u3**************@TK2MSFTNGP10.phx.gbl...
ListBox.Items(0).Value = "Foo"
ListBox.Items(1).Value = "Foo1"

The number (0) is the ordinal reference of the list box item, zero based, starting from the top.

Your code was actually setting the selected value, as would happen if the user clicked the item on the list.

Hope that helps!

Simon.

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...

Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to use
the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.


--
I am using the free version of SPAMfighter for private users.
It has removed 2200 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!
Nov 19 '05 #4
Hi,
you can do something like this:

Dim item As ListItem

For Each item in ListBox1.Items
If item.Text = "something" Then
item.Selected = True
End If
Next

Shawn

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...

Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to use the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.

Nov 19 '05 #5
got it to work, code below seemed to work ok.

listbox.Items.FindByValue("1").Selected = True
listbox.Items.FindByValue("2").Selected = True

"Paul" wrote:

Hi I have a listbox and have the selection mode set to multiple in the
property box.
I am trying to set multiple selected values in code but it only seems to use
the last one.
listbox.SelectedValue = 1
listbox.SelectedValue = 2
thanks.
only 2 gets set above.
--
Paul G
Software engineer.

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: netclectic | last post by:
I'm dynamically adding options to a select list in javascript and i need to be able to set the height of the option, but setting style.height has not effect, I also tried style.pixelHeight but no...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
2
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: RSH | last post by:
Hi, I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net page. Each control has its own unique id. When the user selects a value from each of the dropdownlists it is...
1
by: gauravtechie | last post by:
Hi all, I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change, the code is <html>...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.