Using a DevExpress XtraGrid and Trying to Move Records Up or Down


Author
Message
Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
I have a DevExpress XtraGrid filled with a Business Binding Source. I am trying to follow a Sample that allows user to move a record up or down by clicking a button.

But, the Sample uses a DataTable and not a BBS or BO so I am having trouble converting some of the code.

Dim view As GridView = gridView1
view.GridControl.Focus()
Dim index As Integer = view.FocusedRowHandle
If index <= 0 Then
Return
End If
Dim row1 As DataRow = view.GetDataRow(index)
Dim row2 As DataRow = view.GetDataRow(index - 1)
Dim val1 As Object = row1(OrderFieldName)
Dim val2 As Object = row2(OrderFieldName)
row1(OrderFieldName) = val2
row2(OrderFieldName) = val1
view.FocusedRowHandle = index - 1


What I am not sure how to convert is the lines that involve the DataRows.

I would appreciate any help I could get and if anyone has a Xtragrid allowing moving records I would appreciate any hints or advice.

TIA


Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,

I use the XtraGrid but never had the need to move records up/down nor I have not seen that sample you mention.

The gridview manage the records via its row handle index which it is used to locate the datarow record in the view.  The SF BBS should be able to internally detect the movement of the view row index and translate that to the SF BO.CurrentRowIndex, so I believe your sample code should work just fine.

Please post the link to the DevExpress sample and I will take a look at it.

Edhy Rijo

Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
I did not try the code because I assumed it would not work.

Here is the Link:

https://www.devexpress.com/Support/Center/Example/Details/E764
Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
And by the way Edhy thanks for the help.
Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
This seems to get the correct DataRows. I am not sure it is the correct way to do it?????

Dim row1 As DataRow = Me.ResultsPerfsChecksTimedEventBO1.CurrentRow()
Me.ResultsPerfsChecksTimedEventBO1.MovePrevious()
Dim row2 As DataRow = Me.ResultsPerfsChecksTimedEventBO1.CurrentRow()
Me.ResultsPerfsChecksTimedEventBO1.MoveNext()


I have not figured out how to get the 'Val' values....?

TIA.


Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
Alright the Following Seems to Work but any ideas of a better way to do it or the Correct way to do it would be appreciated.

Dim row1 As DataRow = Me.ResultsPerfsChecksTimedEventBO1.CurrentRow()
Me.ResultsPerfsChecksTimedEventBO1.MovePrevious()
Dim row2 As DataRow = Me.ResultsPerfsChecksTimedEventBO1.CurrentRow()
Me.ResultsPerfsChecksTimedEventBO1.MoveNext()
Dim val1 As Object = row1("JudgesSheetPositionNumber")
Dim val2 As Object = row2("JudgesSheetPositionNumber")
row1("JudgesSheetPositionNumber") = val2
row2("JudgesSheetPositionNumber") = val1


Now on to the part of Mouse Drag and Drop.

 


Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,

I downloaded the demo yesterday but could not get back to it.

I will review it now with your code changes and get back in a few.

Edhy Rijo

Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
thanks Edhy
Edhy Rijo
E
StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)StrataFrame VIP (3.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,

Basically this sample is expecting you have an Order field which they change in the datarow object and it is reflected in the grid because the grid is already ordered by that column named "Order" in their sample.

In your case that column is "JudgesSheetPositionNumber" so basically we would just do the same but at the BO level, assign the "JudgesSheetPositionNumber" value of the selected row to the value next or prior based on the Up/Down button but keep in mind that that will make the BO dirty and you will have to save it to keep the new position number by either asking the user or save it each time the position changes.

When using


' Assuming you are moving Down

Dim
 index As Integer = view.FocusedRowHandle
If index >= view.DataRowCount - 1 Then
      Return
End If

' Here create an instance of the BO with the record where the grid is focused
Dim
 boInGridView As New ResultsPerfsChecksTimedEventBO
boInGridView = TryCast(Me.GridView1.GetRow(index), ResultsPerfsChecksTimedEventBO1)
boInGridView.JudgesSheetPositionNumber = (boInGridView.JudgesSheetPositionNumber + 1)


Obviously you would need to add validations as to make sure when in 1st position you cannot move up or when at the end you cannot move down.

Try to make the functionality works moving Down and Up fist, then focus on make the Drag/Drop operations.

Please let me know if that works for you?

P.S.
Forgot t mention that this whole logic is based on the current sort order enforced in the grid by the sort column "JudgesSheetPositionNumber"  Without this sort in place you will not see the record being moved from one row to another in the grid.

gridView1.Columns("JudgesSheetPositionNumber").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending         
gridView1.OptionsCustomization.AllowSort = False


Edhy Rijo

Edited 10 Years Ago by Edhy Rijo
Buffie
Buffie
StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)StrataFrame User (263 reputation)
Group: StrataFrame Users
Posts: 119, Visits: 11K
Well my code Does Not Work if you try to move the Same Record more then one place.

I will have to look at your code Edhy and see what you have done.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search