for (int i=0; i<Form1->ListBox1->Items->Count; i++)
// If the string does not contain a valid value,
// an EConvertError exception is thrown.
n = Form1->ListBox1->Items->Strings[i].ToInt();
Form1->ListBox2->Sorted = true;
Still, I'd like to see more of your code in order to be able to help properly. Please post the code which is giving you problems, and/or the full error messages you have.
I've looked at and tried to run the code above but it failed to compile for me at this line, ListBox1->Items->Add(k); because variable k is not defined.
now I needed to copy over the numbers as text generated in listbox1 and display in listbox2 as integers and then sort them using the ToInt function
There is a problem with what you are attempting to do, "display in listbox2 as integers" in that the Listbox can only work with strings, so it cannot handle integers directly, the integer value must first be converted to a string.
It seems an unnecessary step, but it is possible to convert from int to string and then back to int if you like.
Perhaps I'm missing something here. Are you intending to use a separate array of integers and sort that array separately, before putting the values into the listbox in order to display the reults?
Maybe you have the original question or description of the project and perhaps would like to share that, as I'm a bit lost as to what it is you actually need to do here.