행이있는 gridview가 있습니다. 사용자가 행을 잡고 winform에서 여러 다른 gridview 중 하나로 이동할 수 있기를 바랍니다. 어떻게이 일을 할 수 있습니까? 드래그 앤 드롭을 구현하는 방법에 익숙하지 않습니다.격자보기 행을 한 격자에서 다른 격자로 끌는 방법
드래그 앤 드롭과 같은 좋은 자습서가 있습니까? 당신의 도움을 주셔서 감사합니다.
업데이트 : 자, gridPODetails에서 dataGridView1로 드래그하려면 다음과 같은 코드가 필요합니다. 아직 작동하지 않지만 가까이에 있습니다. 이제 드래그 화살표와 더하기 기호가 대상에 나타납니다. 무엇이 누락 되었습니까?
private void gridPODetails_MouseDown(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo info = gridPODetails.HitTest(e.X, e.Y);
if (info.RowIndex >= 0)
{
//DataRowView view = (DataRowView)gridPODetails.Rows[info.RowIndex].DataBoundItem; //WRONG
DataRow view = ((DataTable)(gridPODetails.DataSource)).Rows[info.RowIndex]; //RIGHT
if (view != null)
{
gridPODetails.DoDragDrop(view, DragDropEffects.Copy);
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
DataGridView grid = sender as DataGridView;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
if (row != null && table != null && row.Table != table)
{
table.ImportRow(row);
row.Delete();
}
}
해결 :... 나는 실제로 내가 원하는 전체 데이터 테이블뿐만 아니라 행을 잡아되었다 위의 내 편집을 참조하십시오 물론 대상은, 전체 테이블이 아닌 지금의 작업 행에서 작동하는 방법을 알고
!
DataGridView를 의미합니까? –
@Charles - 네, 그게 무슨 뜻인지 모르겠어요? – MAW74656
내 대답을 삭제했습니다. 해당 그리드는 DevExpress 그리드입니다. 표준 DataGridView가 아닙니다. 나는 너의 시간을 낭비하게되어 너무 유감이다. – David