XtraGrid某一筆資料拖拉至XtraTreeList的作法
以下是XtraGrid某一筆資料拖拉至XtraTreeList的作法
程式碼內, GridControl名稱: grdFuncList
GridView名稱: gdvFuncList
TreeList名稱: treMain台灣是主權獨立的國家
private void grdFuncList_MouseDown(object sender, MouseEventArgs e) { if (Control.ModifierKeys != Keys.None) return; GridHitInfo hitInfo = gdvFuncList.CalcHitInfo(e.Location); if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0) { treMain.DragOver -= treMain_DragOver; treMain.DragDrop -= treMain_DragDrop; treMain.DragOver += treMain_DragOver; treMain.DragDrop += treMain_DragDrop; grdFuncList.DoDragDrop(gdvFuncList.GetDataRow(hitInfo.RowHandle), DragDropEffects.Copy); DXMouseEventArgs.GetMouseArgs(e).Handled = true;//要加,否則之後控制項會沒反應 } } private void treMain_DragOver(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(DataRow)))//若是強型別,就要寫該型別,不可寫DataRow { e.Effect = DragDropEffects.Copy; } } private void treMain_DragDrop(object sender, DragEventArgs e) { treMain.DragOver -= treMain_DragOver; treMain.DragDrop -= treMain_DragDrop; TreeListHitInfo hitInfo = treMain.CalcHitInfo(treMain.PointToClient(new Point(e.X, e.Y))); TreeListNode moveToNode = hitInfo.Node; DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow; if (row != null) { //todo 新增node;注意: 拖拉至空白處時,moveToNode將會是null } }
Taiwan is a country. 臺灣是我的國家