0

i am trying to drag a cell from one DevXtraGrid to another without using coordinates using the following code

<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 

how can i used this accordingly any suggestions would be appreciated.

sabby
  • 47
  • 1
  • 11

1 Answers1

0

Try this code:

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

In case you work with Card layout, use this code:

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
Dmitry Nikolaev
  • 3,803
  • 2
  • 19
  • 23
  • i used this code you provided but i am getting an error "Object doesn't support this property or method: 'devXtraGridControl.MainView.ViewInfo.RowsInfo'" please HELP! – sabby Apr 28 '14 at 07:21
  • This is quite odd error since I do not try to access the RowsInfo property in my code. Are you sure that you have not changed the code of the DragNDropCell routine? – Dmitry Nikolaev Apr 28 '14 at 09:00
  • nops i did not change anycode within that routine, i just passed the main grid object, and i get till MainView method only i am not getting the Viewinfo method further.. ' grid.MainView.ViewInfo ' – sabby Apr 28 '14 at 10:24
  • another error i faced was as folows : Object of type 'System.Int16' cannot be converted to type 'DevExpress.XtraGrid.Columns.GridColumn' – sabby Apr 28 '14 at 10:39
  • 1
    Probably, you have another version of the grid control than me. I recommend you contacting the vendor Support (http://support.smartbear.com/message/?prod=TestComplete). – Dmitry Nikolaev Apr 29 '14 at 06:22
  • thanx for the reply man. i have one grid which is a card layout Grid dats y was facing that problem do you know the same for cardview of grid ? – sabby Apr 29 '14 at 13:37
  • I have updated an answer and added a sample for the Card layout. – Dmitry Nikolaev May 02 '14 at 12:09
  • i used GetInfoByHandle(rowindex).cells.item(colindex) i am able to acces all the cards in the gridview but i am not able to access the last row of cards !! please HELP ASAP!!! – sabby May 27 '14 at 10:01