| Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате |
| Форум программистов > C++ Builder > TListBox MultiSelect Help |
| Автор: StrikeTheCore 25.5.2006, 00:05 |
| Hello, These forums were recommended to me due to a lack of Borland C++ forums in English, so I was hoping I could get an answer here. I have created a TListBox and need to select multiple items for a project. Both MultiSelect and ExtendedSelect are set to true, yet when the program runs only one item can be selected at a time. When dragging mutliple items are selected but on MouseButtonUp all are lost. If you have any insight into why this is happening please let me know. Thanks, Brian |
| Автор: chwind 25.5.2006, 10:42 |
| What events assigned to ListBox. Show your code please |
| Автор: StrikeTheCore 26.5.2006, 16:21 |
| I am using OnMouseDown, OnMouseUp, and OnMouseMove. To clarify, what I want is to be able to select multiple items and be able to drag them all in a block to a different position in the list. My code is as follows: 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[i].AnsiCompare(str)) break; mappings[count] = str; mappings[i] = 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. Добавлено @ 16:34 I should also say that the actual problem I am having is that when MultiSelect is set to true you can drag the mouse to select multiple items but when the mouse button is released all selections are lost and the first selected item moves to the last selected item (which is correct behavior without multiselect). What I need to do is allow for the user to select a large block, then be able to drag that entire block to a different position. |
| Автор: chwind 27.5.2006, 16:06 | ||||
| It is a working code. I have checked up cpp file
h file
Only you should finish a code to forbid to move the first 2 elements Has forgotten to tell, elements move the right mouse button. |
| Автор: StrikeTheCore 30.5.2006, 15:44 |
| That worked great and did exactly what I needed. Thanks a lot. -Brian |