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

Need Help with MultiSelect in TListBox

Status
Not open for further replies.

StrikeTheCore

Programmer
May 26, 2006
5
US
I have created a TListBox and set both MultiSelect and ExtendedSelect to true. What I want to do is allow for users to either click one item in the list and be able to drag it to another spot or select multiple items and drag that entire block to another position.

However, when MultiSelect is enabled the user can drag the mouse to select multiple items but as soon as the mouse button is released all are deselected and the first item clicked moves to where the button is released (which is the correct behavior when MultiSelect is not enabled).

My code is as follows (and each method is tied to the corresponding event in the TListBox).

void __fastcall TForm1::MsgTypesMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
AnsiString str;
int i = 0;
if(dragItem == -1)
return;
if(Button == mbLeft)
{
if(dragItem >= MsgTypes->Items->Count)
dragItem = MsgTypes->Items->Count-1;
MsgTypes->Items->Move(startDragItem, dragItem);
for(int count=(startDragItem<dragItem?startDragItem:dragItem); count<=(startDragItem>dragItem?startDragItem:dragItem);count++)
{
i = 0;
str = MsgTypes->Items->Strings[count];
MsgTypes->Items->Strings[count] = AnsiString().sprintf("%03d",msgEnumValues[count])+str.Delete(1,3);
str.Delete(1,1);
for (i = 0; i < 256; i++)
if (mappings.AnsiCompare(str))
break;
mappings[count] = str;
mappings = NULL;
}
dragItem = -1;
startDragItem = -1;
}
}



void __fastcall TForm1::MsgTypesMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TPoint point;
point.x = X;
point.y = Y;
if(Button == mbLeft)
{
dragItem = MsgTypes->ItemAtPos(point, true);
if(dragItem == -1 || dragItem < 2)
{
dragItem = -1;
return;
}
startDragItem = dragItem;
}
}


void __fastcall TForm1::MsgTypesMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TPoint point;
if(dragItem == -1)
return;
point.x = X;
point.y = Y;
if(Shift.Contains(ssLeft)){
dragItem = MsgTypes->ItemAtPos(point, false);
if(dragItem > MsgTypes->Items->Count)
return;
if(dragItem < 2)
dragItem = 2;
}
}


The dragItem and startDragItem are both global ints. Also I want to prevent moving the first 2 items, and that is the reason for the addition if statements. Any help with why this is not working is greatly appreciated.
 
Thanks for the reply but I am looking to be able to drag the items within the same ListBox rather than transfering them to another component. Basically I want the user to be able to rearrange the list based on a priority of their choice.
 
Cool!


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top