2014-04-23 47 views
0

我試圖拖動從一個DevXtraGrid到另一個細胞,而不使用座標使用下面的代碼如何在DevXtraGrid中找到單元格的座標?使用Testcomplete

<code> 
Sub DragAndDropItems(ReqObjectToMove,DestControl) 
Dim XPos ,YPos ,dX ,dY 
LogFolder = Log.CreateFolder("Draging and dropping item ") 
Log.PushLogFolder(LogFolder) 
XPos = ReqObjectToMove.Left+ReqObjectToMove.Width/2 
YPos = ReqObjectToMove.Top+ReqObjectToMove.Height/2 
dX = DestControl.ScreenLeft - ReqObjectToMove.ScreenLeft 
dY = DestControl.ScreenTop - ReqObjectToMove.ScreenTop 
Call ReqObjectToMove.Drag(XPos, YPos, dX, dY) 
Log.PopLogFolder 
End Sub 

我怎樣才能用這個據此任何建議,將不勝感激。

回答

1

試試這個代碼:

Sub Test 
    Set grid = Sys.Process("GridMainDemo").WinFormsObject("frmMain").WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("TableView").WinFormsObject("gridControl1") 
    Sys.Process("GridMainDemo").WinFormsObject("frmMain").Activate 
    Call DragNDropCell(grid, 2, 3, 5, 2) 
End Sub 

Sub DragNDropCell(grid, sourceRow, sourceCol, destRow, destCol) 
    Set source = grid.MainView.ViewInfo.GetGridCellInfo_2(sourceRow, sourceCol) 
    Set dest = grid.MainView.ViewInfo.GetGridCellInfo_2(destRow, destCol) 
    x = source.Bounds.Left + source.Bounds.Width/2 
    y = source.Bounds.Top + source.Bounds.height/2 
    dX = dest.Bounds.Left - source.Bounds.Left + dest.Bounds.Width/2 
    dY = dest.Bounds.Top - source.Bounds.Top + dest.Bounds.Height/2 

    Call grid.Drag(x, y, dX, dY) 
End Sub 

如果你有卡的佈局工作,使用此代碼:

Sub Test_CardLayout 
    Set grid = Sys.Process("GridMainDemo").WinFormsObject("frmMain").WinFormsObject("panelControl1").WinFormsObject("gcContainer").WinFormsObject("CardViewControl").WinFormsObject("gridControl1") 
    Sys.Process("GridMainDemo").WinFormsObject("frmMain").Activate 
    Call DragNDropCellCardLayout(grid, 0, 2) 
End Sub 

Sub DragNDropCellCardLayout(grid, sourceCardIndex, destCardIndex) 
    Set source = grid.MainView.ViewInfo.Cards.Item(sourceCardIndex) 
    Set dest = grid.MainView.ViewInfo.Cards.Item(destCardIndex) 
    x = source.Bounds.Left + source.Bounds.Width/2 
    y = source.Bounds.Top + source.Bounds.height/2 
    dX = dest.Bounds.Left - source.Bounds.Left + dest.Bounds.Width/2 
    dY = dest.Bounds.Top - source.Bounds.Top + dest.Bounds.Height/2 

    Call grid.Drag(x, y, dX, dY) 
End Sub 
+0

我用你提供的驗證碼,但我得到一個錯誤「對象不支持此屬性或方法:'devXtraGridControl.MainView.ViewInfo.RowsInfo'「請幫助! – sabby

+0

這是非常奇怪的錯誤,因爲我不試圖訪問我的代碼中的RowsInfo屬性。你確定你沒有改變DragNDropCell例程的代碼嗎? –

+0

我沒有更改該例程內的任何代碼,我只是通過主網格對象,並且我得到MainView方法只有我沒有進一步得到Viewinfo方法..'grid.MainView.ViewInfo' – sabby

相關問題