473,386 Members | 1,757 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,386 software developers and data experts.

array to listbox

I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I get
all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.
Jul 9 '07 #1
8 1865
CarList.Items[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I
get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.


Jul 9 '07 #2
I can't even compile with this:

CarList.Items[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e5**************@TK2MSFTNGP04.phx.gbl...
CarList.Items[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I
get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.



Jul 9 '07 #3
What's the type of Id[i]? If it is integer, the code should compile. If it
is string, convert it first to integer as
System.Convert.ToInt32(Id[i])

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I can't even compile with this:

CarList.Items[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e5**************@TK2MSFTNGP04.phx.gbl...
>CarList.Items[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>>I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I
get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.




Jul 9 '07 #4
Hi Mike,

See msdn. If Id[i] is type of int it should be compiled.

E.g. this will be compiled:
List<intId = new List<int>();
ListBox1.Items[Id[i]].Selected = true;

and this is not:
List<stringId = new List<string>();
ListBox1.Items[Id[i]].Selected = true;

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

MI can't even compile with this:
M>
MCarList.Items[Id[i]].Selected = true;
M>
MI get error messages
M"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
Mmessage news:e5**************@TK2MSFTNGP04.phx.gbl...
>CarList.Items[Id[i]].Selected = true;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>>I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value
equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how
can I
get all of them selected?
The listbox selectionMode= mulitple
for (int i = 0; i < Id.Length; i++)
{
CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the
array
selected. I want all of the values passed in selected.

Jul 9 '07 #5
My crystal ball tells me this is a type problem (for example split might
well create a string array so you would need to convert Id[i] to an
integer).

Please always post the error message when you have an error ???!!!!

--
Patrice

"Mike" <Mi**@community.nospam.coma écrit dans le message de news:
%2****************@TK2MSFTNGP04.phx.gbl...
>I can't even compile with this:

CarList.Items[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e5**************@TK2MSFTNGP04.phx.gbl...
>CarList.Items[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>>I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I
get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.




Jul 9 '07 #6
its an interger:

I have this:

for (int i = 0; i < Id.Length; i++)
{
CarList.Items[Convert.ToInt32(ID[i])].Selected = true;
}

and I get this when I run it now:
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

and its referring to this line:
CarList.Items[Convert.ToInt32(ID[i])].Selected = true;

the id value is coming through as (1,2,3,4,5,6,7)
then I split it to remove the comma's

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
What's the type of Id[i]? If it is integer, the code should compile. If it
is string, convert it first to integer as
System.Convert.ToInt32(Id[i])

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I can't even compile with this:

CarList.Items[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e5**************@TK2MSFTNGP04.phx.gbl...
>>CarList.Items[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can
I get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.




Jul 9 '07 #7
Hi Mike,

So, that means that length of Id array greater then CarList.Items's length.
See my code in the early message with validation by Id.Contains or such methods.

for (int i = 0; i < CarList.Items.Count; i++)
{
if (Id.Contains(... some checks and convertion... CarList.Items[i].Value )
{
CarList.Items[i].Selected = true;
}
}

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

Mits an interger:
M>
MI have this:
M>
Mfor (int i = 0; i < Id.Length; i++)
M{
MCarList.Items[Convert.ToInt32(ID[i])].Selected = true;
M}
Mand I get this when I run it now:
MIndex was out of range. Must be non-negative and less than the size
Mof the
Mcollection.
MParameter name: index
Mand its referring to this line:
MCarList.Items[Convert.ToInt32(ID[i])].Selected = true;
Mthe id value is coming through as (1,2,3,4,5,6,7)
Mthen I split it to remove the comma's
M"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
Mmessage news:%2****************@TK2MSFTNGP05.phx.gbl...
M>
>What's the type of Id[i]? If it is integer, the code should compile.
If it
is string, convert it first to integer as
System.Convert.ToInt32(Id[i])
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>I can't even compile with this:

CarList.Items[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote
in
message news:e5**************@TK2MSFTNGP04.phx.gbl...
CarList.Items[Id[i]].Selected = true;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...

I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want
to
highlight (select) all the items in the listbox were the value
equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how
can
I get all of them selected?
The listbox selectionMode= mulitple
for (int i = 0; i < Id.Length; i++)
{
CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the
array
selected. I want all of the values passed in selected.

Jul 9 '07 #8
I got this to work finally. My code was actually correct, I just never bound
the listbox, so when my foreach loop was executed, it had no data to loop
through. Thouh I was seeing the data in the listbox, it was cached, so once
I called my grid.databind() it worked.
"Mike" <Mi**@community.nospam.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to
highlight (select) all the items in the listbox were the value equals
(1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I
get all of them selected?
The listbox selectionMode= mulitple

for (int i = 0; i < Id.Length; i++)
{

CarList.SelectedValue = Id[i];
}
this is only getting me the last value being passed in from the array
selected. I want all of the values passed in selected.


Jul 9 '07 #9

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

Similar topics

6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
11
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
1
by: A. Spiehler | last post by:
I'm trying to fill a listBox control with string members from an array of objects. I think using data binding is supposed to be the easiest way to do this. I've never used data binding before and...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
1
by: pauled | last post by:
Hello all, Framework 1.1 VS 2003 Binding listbox. I have an array of objects that I am trying to use as the datasource for a listbox. The array is returned from a webservice and seems to be...
0
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single...
3
by: Sweetiecakes | last post by:
Hi I have an string array containing file paths. I have added them to a ListBox with AddRange(); When I delete an item from the ListBox, how can I delete the same item from the original...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.