473,769 Members | 5,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Selecte dValue = 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 1887
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.comwrot e in message
news:Oa******** ******@TK2MSFTN GP04.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.Selecte dValue = 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.orgwro te in
message news:e5******** ******@TK2MSFTN GP04.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.comwrot e in message
news:Oa******** ******@TK2MSFTN GP04.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.Selecte dValue = 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.comwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>I can't even compile with this:

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

I get error messages
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:e5******** ******@TK2MSFTN GP04.phx.gbl...
>CarList.Item s[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community .nospam.comwrot e in message
news:Oa******* *******@TK2MSFT NGP04.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.Selecte dValue = 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.orgwro te in
Mmessage news:e5******** ******@TK2MSFTN GP04.phx.gbl...
>CarList.Item s[Id[i]].Selected = true;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community .nospam.comwrot e in message
news:Oa******* *******@TK2MSFT NGP04.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.Selec tedValue = 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************* ***@TK2MSFTNGP0 4.phx.gbl...
>I can't even compile with this:

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

I get error messages
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:e5******** ******@TK2MSFTN GP04.phx.gbl...
>CarList.Item s[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community .nospam.comwrot e in message
news:Oa******* *******@TK2MSFT NGP04.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.Selecte dValue = 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.orgwro te in
message news:%2******** ********@TK2MSF TNGP05.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.comwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>I can't even compile with this:

CarList.Item s[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:e5******** ******@TK2MSFTN GP04.phx.gbl...
>>CarList.Ite ms[Id[i]].Selected = true;
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community .nospam.comwrot e in message
news:Oa****** ********@TK2MSF TNGP04.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.Selecte dValue = 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.C ount; 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.orgwro te in
Mmessage news:%2******** ********@TK2MSF TNGP05.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.comwrot e in message
news:%2******* *********@TK2MS FTNGP04.phx.gbl ...
>>I can't even compile with this:

CarList.Ite ms[Id[i]].Selected = true;

I get error messages
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te
in
message news:e5******** ******@TK2MSFTN GP04.phx.gbl...
CarList.Item s[Id[i]].Selected = true;

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mike" <Mi**@community .nospam.comwrot e in message
news:Oa***** *********@TK2MS FTNGP04.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.Sel ectedValue = 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.comwrot e in message
news:Oa******** ******@TK2MSFTN GP04.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.Selecte dValue = 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
7562
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 resulting list will be used to provide a query parameter and the user can choose all locations (the default) or a single, specific location. In the open event of the form containing the listbox I wrote the following code to achieve this. Could...
3
8900
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 Me.ListBoxPerson.Items.AddRange(ary)
11
8556
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 the array list again to refresh. Click on an item in the list, and an Indexing error comes up. (in non-user code, it is trying to get an element from the array that is greater than the number of items in the array.) To reproduce:
1
2780
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 am having trouble getting it to do anything. The relevant code is below, followed by a better explanation of what I'm trying to do. // pseudocode start public delegate string StepMethod();
6
2341
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 populating a listbox with an array of very simple "Country" objects via a WebService. The Country class contains CountryID,TLDs and Name properties each of which have a getter and setter (I found that properties without
1
1516
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 populated ok, see this text from my Autos pane in VS, once the datasource property has been set. - DataSource {System.Array} System.Object
0
5572
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 particular elements in the List Box. Any suggestions on how to best write this? ' I create a Structure with members ' place, title, author, publisher, price, description, lastweek, weeksonlist Structure bestseller Public place...
2
2005
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 particular elements in the List Box. Any suggestions on how to best write this? ' I create a Structure with members ' place, title, author, publisher, price, description, lastweek, weeksonlist Structure bestseller Public place As Integer...
2
6320
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 listbox) like this... <select name="title"> <option value="1"<?php if ($_POST == '1') { echo 'selected="selected"'; } ?>></option> <option value="Mr"<?php if ($_POST == 'Mr') { echo 'selected="selected"'; } ?>>Mr</option>
3
3472
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 array? Thanks
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.