Sorting a listbox

Hi,


I want to sort a list box values. Using the sort property. It sort of works but has some bugs. for example this is how it is displayed. Not in order...

0
1
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
The output is in the expected order. You add strings to a listbox and LBS_SORT (or LBS_STANDARD) style sorts alphabetically - as strings! Strings are sorted left to right by character not numerically.
I did a work around...

I would really like to figure this out on my own but I'm stuck. Trying to read values from the listbox control and display its value in a numericalupdown control. Everything needs to be in hex.

I will try to explain myself.


1
2
3
4
5
6
7
8
9
10
// L"(001)	FC0B = Exit Sign - Defualt Edit",  // The string in the listbox				
		using namespace msclr::interop;
		System::String^ managedString = this->listBox3->SelectedItem->ToString();
		System::String^ sub1 = managedString->Substring(1, 2);
		//std::string standardString = marshal_as<std::string>(sub1);
		
		std::string str_number = marshal_as<std::string>(sub1);
		int integer_value;
		integer_value = std::stoi(str_number);
		NumericUpDow3->Value = integer_value;








Edit: Nevermind. Fixed! User error lol.


This is the working code.

1
2
3
4
5
6
7
8
// L"(001)	FC0B = Exit Sign - Defualt Edit",				
		using namespace msclr::interop;
		System::String^ managedString = this->listBox3->SelectedItem->ToString();
		System::String^ sub1 = managedString->Substring(5, 5);
		std::string str_number = marshal_as<std::string>(sub1);
		long long int integer_value;
		integer_value = std::stoi(str_number, nullptr, 16);
		NumericUpDow1->Value = integer_value;
Last edited on
Registered users can post here. Sign in or register to post.