how to move the contents of listbox to arrays and get highest two entries...
listbox and arrays
Collapse
X
-
Tags: None
-
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(listB ox1.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 CodingComment
-
Originally posted by todashahAs 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(listB ox1.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 CodingComment
-
Originally posted by todashahAs 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(listB ox1.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 CodingComment
-
It's pretty straight forward.
This should be code for using the "top" two elements.
[code=vbnet]
Dim mystr1 as String("")
Dim mystr2 as String("")
'I think Array indexes in VB start with 1, if they start with 0 like they should
'Then just change the 1 and 2 to 0 and 1
mystr1=listBox1 .Items(1).ToStr ing()
mystr1=listBox1 .Items(2).ToStr ing()
[/code]Comment
-
Originally posted by PlaterIt's pretty straight forward.
This should be code for using the "top" two elements.
[code=vbnet]
Dim mystr1 as String("")
Dim mystr2 as String("")
'I think Array indexes in VB start with 1, if they start with 0 like they should
'Then just change the 1 and 2 to 0 and 1
mystr1=listBox1 .Items(1).ToStr ing()
mystr1=listBox1 .Items(2).ToStr ing()
[/code]
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....Comment
Comment