Hallo !
Habe 2 Listboxen in Verwendung, die Daten beinhalten und zwischen den Listboxen bestimmten Inhalten zugeornet sind.
zBsp.: Listbox1: C:\Daten5\a.txt
C:\Daten5\b.txt
......
Listbox2: a.txt
b.txt
......
Möchte mittels Mouse in der Listbox2 eine bestimmte Datei selectiren und an einer anderen Stelle in der Listbox2 neu plazieren.
Beide Listboxen gemeinsam selectieren funktioniert. Das gemeinsame verschieben klappt nicht, wobei wenn ich jede einzelne Listbox selectiere dann geht es.
Wo liegt der Fehler, wenn ich Listbox2 selectiere und verschiebe in Listbox1 nichts passiert.
Hier der Code: ( unter Verwendung einer ActionList-Komponente )
Delphi-Quellcode:
procedure TFMain.ListBox2Click(Sender: TObject);
begin
if not ( Listbox2.ItemIndex = Listbox2.Count - 0 ) then
begin
Listbox1.ItemIndex := Listbox2.ItemIndex;
end;
end;
function ListMenu(mi: TMenuItem): Integer;
var
i: Integer;
item: TMenuItem;
begin
Result := 0;
for i := 0 to Pred(mi.Count) do
begin
item := mi.Items[i];
if item.Count = 0
then item.Visible := item.Enabled
else item.Visible := ListMenu(item) > 0;
Inc(Result, Ord(item.Visible and not item.IsLine));
end;
end;
procedure TFMain.MoveUpActionUpdate(Sender: TObject);
var
at: TListBox;
begin
with Sender as TAction do
begin
at := ActiveControl as TListBox;
Enabled := at.ItemIndex > 0;
end;
end;
procedure TFMain.MoveDownActionUpdate(Sender: TObject);
var
at: TListBox;
begin
with Sender as TAction do
begin
at := ActiveControl as TListBox;
Enabled := (at.ItemIndex >= 0) and (at.ItemIndex < Pred(at.Count));
end;
end;
procedure TFMain.MoveDownActionExecute(Sender: TObject);
var
at: TListBox;
begin
with Sender as TAction do
at := ActiveControl as TListBox;
with at do
Listbox2.Items.Exchange(Listbox2.ItemIndex, Succ(Listbox2.ItemIndex));
Listbox1.Items.Exchange(Listbox1.ItemIndex, Succ(Listbox1.ItemIndex));
end;
procedure TFMain.MoveUpActionExecute(Sender: TObject);
var
at: TListBox;
begin
with Sender as TAction do
at := ActiveControl as TListBox;
with at do
Listbox2.Items.Exchange(Listbox2.ItemIndex, Pred(Listbox2.ItemIndex));
Listbox1.Items.Exchange(Listbox1.ItemIndex, Pred(Listbox1.ItemIndex));
end;
procedure TFMain.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
index: Integer;
begin
with Sender as TListBox do
index := ItemAtPos(Point(X, Y), True);
Accept := (Sender = Source) and (index > -1);
end;
procedure TFMain.ListBox1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
index: Integer;
begin
with Sender as TListBox do
begin
index := ItemAtPos(Point(X, Y), True);
Items.Move(ItemIndex, index);
end;
end;
procedure TFMain.ListBox1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
begin
with Sender as TListBox do
Listbox2.ItemIndex := ItemAtPos(MousePos, False);
end;
procedure TFMain.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
index: Integer;
begin
with Sender as TListBox do
begin
index := ItemAtPos(Point(X, Y), True);
Items.Move(ItemIndex, index);
end;
end;
procedure TFMain.ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
index: Integer;
begin
with Sender as TListBox do
index := ItemAtPos(Point(X, Y), True);
Accept := (Sender = Source) and (index > -1);
end;
procedure TFMain.ListBox2ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
begin
with Sender as TListBox do
//Listbox1.ItemIndex := Listbox2.ItemAtPos(MousePos, False);
Listbox1.ItemIndex := Listbox2.ItemIndex;
end;
Einem Hinweis wäre ich dankbar !
ml