Forum > LCL

ListView Drag Drop

(1/3) > >>

Weitentaaal:
Hello guys :)

So through my Prev. Post : https://forum.lazarus.freepascal.org/index.php/topic,54449.msg404533.html#msg404533
I was able to Separate Data and Gui but didn't managed to implement this with Drag and Drop. I Know how to make 2 ListViews able to drag and drop but i dont get it how u match ID's of my items with ItemIndex of ListView and how do i Display those Items the correct way ?

With Separation in those 2 ListViews i ment Something like :


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TForm1.ListView2Data(Sender: TObject; Item: TListItem);var  i: SizeInt;begin  i := Item.Index;     IF (FData[i].aProperty = ThisandThisState) then begin        //Add To This List    end else begin        //Add to other list    end;end; 

ASerge:
A little slurred, I don't understand what is needed.
First, I will answer the last question from a closed topic. Why virtual? So that the data representation component does not waste its memory. In addition, it will exclude all sorts of "phantoms".

As far as I understand, you have two ListViews of the data. If you want to use a single data source (FData), then you need a selection criterion. If not, I don't see the problem: when dragged the data from FData1 (the indexes of the selected elements are the indexes in the data array), move it to FData2, and then adjust the number of elements in the virtual Listviews.

Weitentaaal:
What i ment was that i  have 2 Lists.

1 Displays All Items wich are here and if u drag it to the Second it wont be Displayed anymore at First List.
It's like a Checkstate (First List unchecked second checked). So i thought i use a Data Array wich i get from my Database, in wich all of my items are represented.

I Have a Property (boolean) wich will provide me info about the "checkstate" of the Item if True then it should get Displayed in Second Form, if False then in the First.

In Short: 2 ListViews, 1 Data Array (How do i provide ListViews with info and make those basic operations (Add, Delete, Edit(Data), Put item from 1 list in the other))
But i don't realy get it how i should do the Data Linking. Pls Help Thanks

y.ivanov:
Since TListItem.Data is of type Pointer you should typecast:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ListView2Data(Sender: TObject; Item: TListItem);var  i: SizeInt;begin  //i := Item.Index;  i := PtrInt(Item.Data);  
And when assigning to it:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  Item.Data := Pointer(PtrInt(i)); 
as korba812 pointed out in: https://forum.lazarus.freepascal.org/index.php/topic,54449.msg404508.html#msg404508

Weitentaaal:
I Know how to cast thanks :)

How do i manage my Indexes ? My ID's should not change itself.

And why doesn't my ListView dispülay things when i set it to vsReport

Edit : Now using ListBox, works better. But i don't understand why i don't have to Free my Object before Deleting an item.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    if (Source is TListBox)  and (TListBox(Source).ItemIndex > -1) then begin // Wenn der Objekttyp stimmt werden die Daten übernommen      Data := GetData(TListBox(Source).Items.Objects[TListBox(Source).ItemIndex]);      Data^.Ausgewaehlt:= True;       ListBox2.Items.AddObject(Data^.Name, TObject(Data)); // Fügt den Text aus dem Edit hinzu       TListBox(Source).Items.Delete(TListBox(Source).ItemIndex);   end; 
Do i have to Free The Object before Deleting Item ? bc when i did that i got an error now it works (i guess :-[). Or can i just delete item bc Object is used from another Item

Navigation

[0] Message Index

[#] Next page

Go to full version