Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox Sync Sort Order 1

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I've already solved this in my own way, but I thought I'd ask if there was a real simple way to handle this problem that I maybe didn't think of (maybe though the controls?):

Let's say, I have a ComboBox (or a ListBox or anything of that nature), which I want to show the user in a sorted fashion with some strings in it. The catch is, what I want to load are strings that have no relationship to the data that those strings represent in the program/system.

So, to establish the relationship between each of the items, I can establish a TStringList and place my real items in that, and my "friendly" list of items into the ComboBox the user sees in a one-to-one relationship. Like:

Friendly1 ---> Real1
Friendly2 ---> Real2
etc.

Now, I want to show the strings in the "friendly" list in a sorted fashion. I can set Sorted to true, but that does nothing to preserve the relationship in the other list.

So, is there an easier way to solve it than to physically do the sort, as I did?


 
why not use the Items.objects property? their order is preserved when sorting the strings.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
why not use the Items.objects property? their order is preserved when sorting the strings.

I tried this, and I didn't quite get the expected result - I ended up with a bunch of totally random strings in the objects property. Of course, I had to typecast the strings because objects is a TObject, but I'm not sure that was the problem.

My guess, though, is that since Ansi strings are dynamic and the positions of the data itself got changed between the load and execution?

But anyhow, as I mentioned, I solved the problem in my own way (loading two stringlists, then sorting the friendly list and moving the real list items along with the friendly list items).
 
I ended up with a bunch of totally random strings in the objects property

My guess, though, is that since Ansi strings are dynamic and the positions of the data itself got changed between the load and execution?

correct.

another workaround is to make a small class, add a string property (and other related data), create it and add that one to the objects property.



-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top