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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help

Status
Not open for further replies.

igornastoski

Technical User
Mar 21, 2002
6
SI
Hi,
let me explain my problem.I have one ListBox (ListBox1 with several Items). I would like to rearrange Item's starting position (in the same ListBox1) in random order. I have tried to solve my problem with drag&drop operation but in that way, selected Item will always be placed at the end of the column (the others will just move one position up), and not in a position where I draged it (like in Winamp listbox). After using the OnMouseDown and OnDragDrop event I've created an OnDragDrop event with code (here is the problem I think):


void_fastcall TForm1::ListBox1DragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
TListBox *sender=(TListBox *) Sender;
TListBox *source=(TListBox *) Source;

sender->Items->Add(source->Items->Strings[source->ItemIndex]);

source->Items->Delete(source->ItemIndex);
}

Is there some other solution for that?
Thanks, for helping me out.
best Regards,
Igor
 
Try saving your items in an array of strings, then clear your listbox and add the items in the array one at a time based on a random index number of the array.

Use the randomize() function (look in help) to obtain the random index number.

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top