Autor Beitrag
Ivy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 08.06.11 14:23 
Hallo,
ich habe 2 listviews, einmal die datenquelle und das ziel. In der quelle befinden sich images die aus einer imagelist bezogen werden. diese images möchte ich gerne in die zweite listview verschieben. Mit Text funktioniert das ganze mit diesem codeausschnitt:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
private void ListView_ItemDrag(object sender, ItemDragEventArgs e) { 
  ListView listview = (ListView)sender; 
  ListViewItem[] items = new ListViewItem[listview.SelectedItems.Count]; 
  for(int i = 0; i < listview.SelectedItems.Count; i++) 
    items[i] = listview.SelectedItems[i]; 
  listview.DoDragDrop(new DataObject("ListViewItemData", items), 
  DragDropEffects.Move); 
}

private void listView_DragEnter(object sender, DragEventArgs e) { 
  if(e.Data.GetDataPresent("ListViewItemData")) 
    e.Effect = DragDropEffects.Move; 
  else 
    e.Effect = DragDropEffects.None; 
}

private void listView_DragDrop(object sender, DragEventArgs e) { 
  ListView listview = (ListView)sender; 
  ListViewItem[] items = (ListViewItem[])(e.Data.GetData("ListViewItemData")); 
  for(int i = 0; i < items.Length; i++) { 
    listview.Items.Add(items[i].Text); 
  if(listview == listView1) 
    listView2.Items.Remove(listView2.SelectedItems[0]); 
  else 
    listView1.Items.Remove(listView1.SelectedItems[0]); 
}


jedoch mit den images klappt das nicht. weiß jemand an was das liegt?

Danke


Zuletzt bearbeitet von Ivy am Mi 06.07.11 13:23, insgesamt 1-mal bearbeitet
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 06.07.11 13:22 
keiner ne idee?? :(
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 06.07.11 14:04 
Hallo Ivy,

was genau funktioniert denn nicht ("klappt nicht" ist keine Fehlerbeschreibung)?
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 06.07.11 14:15 
also ne fehlermeldung kommt keine direkt... das image erscheint einfach nicht in der zweiten listbox^^
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 06.07.11 14:20 
Wie sieht denn dein Code für die Images aus?
Und hast du beiden ListViews dieselbe ImageList zugewiesen?

Oder suchst du einfach
ausblenden C#-Quelltext
1:
listview.Items.Add(items[i].Text, items[i].ImageIndex);					

?


Zuletzt bearbeitet von Th69 am Mi 06.07.11 14:23, insgesamt 1-mal bearbeitet
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 06.07.11 14:22 
die images werden über die imagelist eingepfelgt, dort befinden sich die ganzen bilder und die wird dann mit der listview verknüpft. gibt also keinen code, aber die bilder erscheinen bereits in meiner quelllistview....
allowdrop eigenschaft im ziel listview hab ich auch aktiviert.

edit:
ja ich habe eben bei largeImageList in meiner ziellistview, meine imagelist angegeben, ich denke das ist zugewiesen^^
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 06.07.11 15:55 
In deinem Code oben hast du die Bilder ja auch nirgends zugewiesen. Hast du das einmal ausprobiert wie user profile iconTh69 ja gezeigt hat?
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 06.07.11 16:03 
ja habs jetzt so, tut sich aber immer noch nichts...

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
    private void ListViewZiel_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("ListViewItemData"))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }

        private void ListViewZiel_DragDrop(object sender, DragEventArgs e)
        {
            ListView listview = (ListView)sender;
            ListViewItem[] items = (ListViewItem[])(e.Data.GetData("ListViewItemData"));
            for (int i = 0; i < items.Length; i++)
            {
                       ListViewZiel.Items.Add(items[i].Text, items[i].ImageIndex);
                if (listview == listViewQuelle)
                    ListViewZiel.Items.Remove(ListViewZiel.SelectedItems[0]);
                else
                    listViewQuelle.Items.Remove(listViewQuelle.SelectedItems[0]);
            }
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 06.07.11 16:47 
Bei mir funktioniert der Code. :nixweiss:

Da bei dir aber weder ListViewZiel noch ListViewQuelle definiert sind, ist das wohl nicht ganz der echte Code, oder? Die Variablen habe ich in DragDrop natürlich noch hinzufügen müssen, aber dann ging alles.
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Mi 06.07.11 16:52 
so hier nochmal der vollständige code:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            ListView ListViewZiel = (ListView)sender;
            ListViewItem[] items = new ListViewItem[ListViewZiel.SelectedItems.Count];
            for (int i = 0; i < ListViewZiel.SelectedItems.Count; i++)
                items[i] = ListViewZiel.SelectedItems[i];
            ListViewZiel.DoDragDrop(new DataObject("ListViewItemData", items),
            DragDropEffects.Move);
        }

 private void ListViewZiel_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("ListViewItemData"))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }

 private void ListViewZiel_DragDrop(object sender, DragEventArgs e)
        {
            ListView listview = (ListView)sender;
            ListViewItem[] items = (ListViewItem[])(e.Data.GetData("ListViewItemData"));
            for (int i = 0; i < items.Length; i++)
            {
                ListViewZiel.Items.Add(items[i].Text, items[i].ImageIndex);
                if (listview == listViewQuelle)
                    ListViewZiel.Items.Remove(ListViewZiel.SelectedItems[0]);
                else
                    listViewQuelle.Items.Remove(listViewQuelle.SelectedItems[0]);
            }



        }
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 06.07.11 17:42 
Hallo Ivy,

wenn du jetzt deinen beiden ListViews dieselbe ImageList zugewiesen hast (SmallImageList bzw. LargeImageList - je nach ListItem.View, s. MSDN), dann sollte dein Code jetzt mit meiner Änderung auch bei dir funktionieren.
Ansonsten debugge mal den Code bei dir und schau ob beim DragDrop wirklich ein Wert in ImageIndex (!= -1) übermittelt wird.
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 07.07.11 14:15 
Also der ImageIndex ist -1
die imageliste weise ich ja einfach über die eigenschaften zu, oder??
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 07.07.11 14:38 
Bei mir nicht, da ist der korrekte Wert drin. Mit welchem Tool arbeitest du denn? Auch Visual C# 2010? (Die Angabe steht ja leider bei dir nicht im Profil.)

// EDIT:
Siehe dort, das ist 1:1 dein letzter Quelltext, direkt kopiert ohne Anpassungen.

ImageIndex

// EDIT 2:
Ja, SmallImageList bzw. LargeImageList muss einfach nur bei beiden Listviews zugewiesen sein.
Einloggen, um Attachments anzusehen!
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 07.07.11 15:08 
hm das ist echt sehr komisch... bei mir bleibt er bei -1
versteh ich solangsam nicht mehr, weil ich habs ja wirklich genau gleich^^
Einloggen, um Attachments anzusehen!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 07.07.11 15:27 
Im Anhang einmal das komplette Projekt inkl. .exe im Releaseordner.
Einloggen, um Attachments anzusehen!
Ivy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Do 07.07.11 15:34 
super vielen dank dann werd ich mal schauen ob ich den fehler finde...