Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-10-10 11:51:32, last edited by Zumza (2015-10-10 11:51:57)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

[C# Form] Visually rearranging a list?

I have a list of elements and I want to display them in a C# form.
Eg.:

abc
bcd
cde
def

I want to live rearrange them thought drag & drop.
Here's a video:


So... Theres a Win Form Element for that? I don't need fancy images, the elements would be just strings.

Thanks!


Everybody edits, but some edit more than others

Offline

#2 2015-10-10 14:08:49

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: [C# Form] Visually rearranging a list?

your question, from stack overflow
here

basically, you could use a listview, or a really hacked listbox

Offline

#3 2015-10-10 16:49:31, last edited by Zumza (2015-10-10 16:50:37)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

Re: [C# Form] Visually rearranging a list?

hummerz5 wrote:

your question, from stack overflow
here

basically, you could use a list view, or a really hacked listbox

Thanks.


For those who may want same thing Ill post the code:

private void listBox1_MouseDown(object sender, MouseEventArgs e) {
            if (listBox1.SelectedItem == null) return;
            listBox1.DoDragDrop(listBox1.SelectedItem, DragDropEffects.Move);
}

private void listBox1_DragOver(object sender, DragEventArgs e) {
            e.Effect = DragDropEffects.Move;
}

private void listBox1_DragDrop(object sender, DragEventArgs e) {
            Point point = listBox1.PointToClient(new Point(e.X, e.Y));
            int index = listBox1.IndexFromPoint(point);
            if (index < 0) index = listBox1.Items.Count - 1;
            object data = e.Data.GetData(typeof(string));
            this.listBox1.Items.Remove(data);
            this.listBox1.Items.Insert(index, data);
}

Don't forget to AllowDrop in listbox propriety.


Everybody edits, but some edit more than others

Offline

Wooted by:

#4 2015-10-10 18:17:38

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: [C# Form] Visually rearranging a list?

wow, you went hack 2.0 on this
cool

Offline

hummerz51444497458548284

Board footer

Powered by FluxBB

[ Started around 1732451429.8859 - Generated in 0.043 seconds, 13 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]