473,473 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

listbox and arrays

4 New Member
how to move the contents of listbox to arrays and get highest two entries...
Mar 31 '08 #1
6 2349
Plater
7,872 Recognized Expert Expert
Listboxs already store there items in an array (well, Collection, but they work the same for most things). You can just access index 0 and 1 (or 1 and 2 if in VBNET?) of the items.
Mar 31 '08 #2
todashah
26 New Member
As far as C# is concern write down following code to copy content
of listbox to array....

int k = listBox1.Items.Count;
int[] i = new int[10];
int a = 0;
for (int j = 0; j < k; j++)
{
i[a++] = int.Parse(listBox1.Items[j].ToString());
}

Here i have assume that listbox contain integer value. Once data store
in array now i have left remaining work for u to find two highest value..

Bye....Enjoy Coding
Apr 1 '08 #3
saurabhkunal
4 New Member
As far as C# is concern write down following code to copy content
of listbox to array....

int k = listBox1.Items.Count;
int[] i = new int[10];
int a = 0;
for (int j = 0; j < k; j++)
{
i[a++] = int.Parse(listBox1.Items[j].ToString());
}

Here i have assume that listbox contain integer value. Once data store
in array now i have left remaining work for u to find two highest value..

Bye....Enjoy Coding
can u please tell me how to write the same code in vb.net....
Apr 1 '08 #4
saurabhkunal
4 New Member
As far as C# is concern write down following code to copy content
of listbox to array....

int k = listBox1.Items.Count;
int[] i = new int[10];
int a = 0;
for (int j = 0; j < k; j++)
{
i[a++] = int.Parse(listBox1.Items[j].ToString());
}

Here i have assume that listbox contain integer value. Once data store
in array now i have left remaining work for u to find two highest value..

Bye....Enjoy Coding
can u please tell me how to write the code in vb.net.actually i need the above code in vb.net.....
Apr 1 '08 #5
Plater
7,872 Recognized Expert Expert
It's pretty straight forward.

This should be code for using the "top" two elements.
Expand|Select|Wrap|Line Numbers
  1. Dim mystr1 as String("")
  2. Dim mystr2 as String("")
  3.  
  4. 'I think Array indexes in VB start with 1, if they start with 0 like they should
  5. 'Then just change the 1 and 2 to 0 and 1
  6. mystr1=listBox1.Items(1).ToString()
  7. mystr1=listBox1.Items(2).ToString()
  8.  
Apr 1 '08 #6
saurabhkunal
4 New Member
It's pretty straight forward.

This should be code for using the "top" two elements.
Expand|Select|Wrap|Line Numbers
  1. Dim mystr1 as String("")
  2. Dim mystr2 as String("")
  3.  
  4. 'I think Array indexes in VB start with 1, if they start with 0 like they should
  5. 'Then just change the 1 and 2 to 0 and 1
  6. mystr1=listBox1.Items(1).ToString()
  7. mystr1=listBox1.Items(2).ToString()
  8.  
i have retrieved 3 marks of a student and i have to select best two
out of them.i used the sort property of listbox so that marks comes
in sorted order and i can take the best two marks but its not working.
how can i take best two marks from the listbox.another way which i thought
was to transfer the contents of listbox to array sort it and take the values
at indices 1 and 2 which will be highest and second highest
but i was not able to write the code for that.how can i
do this or can u tell me any other method to do this....
Apr 1 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
2
by: Kevin Quigley | last post by:
Hi, I have an application that allows users to select items from one listbox and in doing so the item is removed from the original list and displayed in the other. I had this working in the...
7
by: 00_ChInkPoIntD12 | last post by:
Can anyone confirm there isn't a Sort() method for WebControl Listbox in Asp.net? It is rather simple to write a method to do the sorting, but just wondering I shouldn't invent the wheel if...
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...
4
by: Just Me | last post by:
I populate a ListBox with Objects (not Strings) that has a String field (which is displayed) and an Integer field (which is not displayed). I need to have the displayed items in the Listbox...
3
by: Doudou | last post by:
Hello, (I'm french, so my english isn't very good) I use a dataTable to fill a listbox (listbox databinded). This listbox has a valuemember (integer) and a displaymember (string) differents. ...
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...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: captainphoenix | last post by:
all in vb2005 I have three arrays: one 2d array, two 1d arrays. I need to output them into a listbox and align them to columns, which I know how to do using string.format(blahblahblah). However, in...
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
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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 ...
0
muto222
php
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.