OK, here we go.
//▼--------------------------------Schedule DGV------------------------------------▼//
private void dgvSchedule_DragEnter(object sender, DragEventArgs e)
{
bDragList = true;
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void dgvSchedule_DragDrop(object sender, DragEventArgs e)
{
Point pt = dgvSchedule.PointToClient(new Point(e.X, e.Y));
htiSchedule = dgvSchedule.HitTest(pt.X, pt.Y);
if ((htiSchedule.ColumnIndex == 0) && (bDragSchedule == true))
{
MessageBox.Show("CANT COPY DATA HERE");
bDragSchedule = false;
}
else
{
string str = (string)dgvSchedule.Rows[htiSchedule.RowIndex].Cells[htiSchedule.ColumnIndex].Value;
if ((str != null) && (bDragSchedule == true))
{
MessageBox.Show("DATA ALREADY IN");
bDragSchedule = false;
}
else if ((str == null) && (bDragSchedule == true))
{
dgvSchedule.Rows[htiSchedule.RowIndex].Cells[htiSchedule.ColumnIndex].Value = e.Data.GetData(DataFormats.Text);
bDataDrop = true;
bDragSchedule = false;
}
}
}
private void dgvSchedule_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridView.HitTestInfo info = dgvSchedule.HitTest(e.X, e.Y);
if (info.RowIndex >= 0 && info.ColumnIndex >= 0)
{
string text = (String)dgvSchedule.Rows[info.RowIndex].Cells[info.ColumnIndex].Value;
if (text != null)
{
dgvSchedule.DoDragDrop(text, DragDropEffects.Copy);
dgvSchedule.ClearSelection();
if (bDataDrop == true)
{
dgvSchedule.Rows[info.RowIndex].Cells[info.ColumnIndex].Value = null;
dgvSchedule.ClearSelection();
bDataDrop = false;
}
}
}
}
}
private void dgvSchedule_DragOver(object sender, DragEventArgs e)
{
bDragSchedule = true;
}
//▲-----------------------------End of DGV Schedule-------------------------------------▲//
//▼-----------------------------Data List DGV------------------------------------▼//
private void dgvItemList_DragEnter(object sender, DragEventArgs e)
{
bDragSchedule = true;
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void dgvItemList_DragDrop(object sender, DragEventArgs e)
{
if (bDragList == true)
{
dgvItemList.Rows.Add(1);
int iLastRowIndex = dgvItemList.RowCount;
dgvItemList.Rows[iLastRowIndex - 1].Cells[0].Value = e.Data.GetData(DataFormats.Text);
bDataDrop = true;
bDragList = false;
}
}
private void dgvItemList_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridView.HitTestInfo info = dgvItemList.HitTest(e.X, e.Y);
if (info.RowIndex >= 0 && info.ColumnIndex >= 0)
{
string text = (String)dgvItemList.Rows[info.RowIndex].Cells[info.ColumnIndex].Value;
if (text != null)
{
dgvItemList.DoDragDrop(text, DragDropEffects.Copy);
if (bDataDrop == true)
{
dgvItemList.Rows.RemoveAt(info.RowIndex);
bDataDrop = false;
}
}
}
}
}
//▲----------------------------End of DGV List-------------------------------------------------▲//
Lemme know if there are any questions.
Cheers!