Home Forums WinForms controls Xceed Grid for WinForms Moving rows in detailgrid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Xceed Support
    Post count: 5658
    #15048 |

    Hi there,

    I have a problem with databound and detail grids. I don’t know exactly if my thinking is wrong or if there is no solution. Here is my problem:

    I have a grid Control which is build like a tree control (See Explorer example in Xceed documentation). There are different reasons not to use a treeView, but there are unimportant here.
    This means that there is a System-Grid which have a Port detailgrid. The Port grid itself has a detailgrid called Devices. All grids are bound to a dataset structure.

    Now f.e. I will move a “Device xy” from “Port 1” to “Port 2”. Therefore I check CurrentRow, search the corresponding DataRow and change its parent. Source Code look like this:

    private void toolMoveUp_Click(object sender, Xceed.SmartUI.SmartItemClickEventArgs e)
    Xceed.Grid.DataRow xrow = gridControl.CurrentRow as Xceed.Grid.DataRow;
    DataRowView rowView = xrow.SourceObject as DataRowView;
    DataRow dataRow = rowView.Row;
    System.Data.DataRelation rel = dataRow.Table.ParentRelations[0];
    DataRow parent = dataRow.GetParentRow(rel);

    int i;
    for (i=0;i<parent.Table.Rows.Count;i++)
    if (parent.Table.Rows[i] == parent)

    if (i>0)
    parent = parent.Table.Rows[i-1];

    This code works fine, but I want that the moved row will remain selected. Currently the selection still remains on the “old” position (this means before moving the row).
    I found no way to get the new position of the moved cell and have also no idea about how to get the corresponding Xceed.Grid.DataRow from a System.Data.DataRow.

    Any idea’s?
    Idea’s about optimizing this procedure are also welcome.

    Thx Frank Weingaertner

    Imported from legacy forums. Posted by Frank (had 1867 views)

    User (Old forums)
    Post count: 23064

    Moving rows right into the data source makes it difficult to find the right row, and the only solution we see is to go through the whole grid to find it.

    One solution would be to use the grid to move the row.

    For example, for a MoveUp, you could find the ParentGrid.ParentDataRow, get the row above this one, and set the foreign key value of the row to be moved to the value of the above row. This way, the grid will move the row into the right detail grid, and you will be able to select it again.

    Another solution would be to store the cell values into a buffer, delete the row, and add a new row in the detail grid you want, set its values, then select it.

    Imported from legacy forums. Posted by André (had 2940 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.