I don't have any idea what's wrong with this code. Can someone please help fix it, I have my entire form set to "Allow Drop = true". So i should just be able to drag a list view item anywhere and have the information displayed in the text boxes. Nothing happens when clicking a list view item and dragging it.
Form Layout:
ListView control on the left side with 5 names, 5 text boxes on the right side with labels corresponding to them. When a list view item is clicked and dragged anywhere on the form, their information should be displayed in the proper text boxes.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Part_B
{
public partial class Form1 : Form
{
const int ASCIIO = 48;
private struct people
{
public string fName;
public string lName;
public string number;
public string years;
public string degree;
}
private people[] list = new people[5];
public Form1()
{
InitializeComponent();
list[0].fName = "John";
list[0].lName = "Doe";
list[0].number = "245-9087";
list[0].years = "4";
list[0].degree = "Computer Science";
list[1].fName = "Jane";
list[1].lName = "Smith";
list[1].number = "222-2222";
list[1].years = "1";
list[1].degree = "Arts";
list[2].fName = "Mike";
list[2].lName = "Butler";
list[2].number = "802-1233";
list[2].years = "4";
list[2].degree = "Economics";
list[3].fName = "Alan";
list[3].lName = "Kay";
list[3].number = "455-3939";
list[3].years = "3";
list[3].degree = "Phsycology";
list[4].fName = "Jill";
list[4].lName = "Jacobs";
list[4].number = "285-3944";
list[4].years = "2";
list[4].degree = "Computer Sciece";
}
private void listView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
listView1.DoDragDrop(listView1.FocusedItem.Index.ToString(), DragDropEffects.Copy);
}
private void Form1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(string)))
e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
int index = ((int)e.Data.GetData(DataFormats.Text).ToString()[0]) - ASCIIO;
fName.Text = list[index].fName;
lName.Text = list[index].lName;
pNumber.Text = list[index].number;
yCollege.Text = list[index].years;
Degree.Text = list[index].degree;
}
private void Form_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}