windowsforms-devexpress-dot-xtraverticalgrid-dot-rows-dot-rowproperties-0b29c443.md
Gets the position of the associated field within a data source.
Namespace : DevExpress.XtraVerticalGrid.Rows
Assembly : DevExpress.XtraVerticalGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid
[Browsable(false)]
public virtual int RowHandle { get; }
<Browsable(False)>
Public Overridable ReadOnly Property RowHandle As Integer
| Type | Description |
|---|---|
| Int32 |
An integer value representing the zero-based index of the corresponding field within a data source.
|
When a vertical grid control is in bound mode, it can display field values from the associated data source with the help of row items. Row items can be bound to data source fields via the RowProperties.FieldName property. If a row item is bound to a field, the RowHandle property returns the index of the bound field within the associated data source, otherwise it returns -1.
When working in Unbound Mode, the VGridControl.DataSource property is set to null ( Nothing in Visual Basic). Hence, row items are not bound to any field. In this case, the RowHandle property of any row item returns -1.
You can use specific overloaded variants of the VGridControlBase.GetCellValue and VGridControlBase.SetCellValue methods to correspondingly obtain or set the value of the data cell specified by its row handle and the corresponding record’s index.
The following example demonstrates how to use the RowProperties.RowHandle property to organize grid rows into the sequence order of their associated data fields. This example assumes that the following conditions should or may take place:
This example visits each grid row and performs an operation represented by the RowOperationRestoreOrder class instance. This class is the RowOperation class descendant. Row operations implemeted by this class hide all category rows to the Customization Form, separate multi-editor rows (if any) into individual editor rows and move all rows to the top level.
Finally, rows in the VGridControlBase.Rows collection are reordered to follow the order of associated fields in the linked data source.
The image below shows how rows are organized in the grid control before and after code execution.
// implementing RowOperationRestoreOrder class
public class RowOperationRestoreOrder : RowOperation {
private VGridControl vGrid;
// reserving a list for category and editor rows processing
private ArrayList childRows;
// reserving a list for multi-editor rows processing
private ArrayList meRows;
public RowOperationRestoreOrder(VGridControl grid) : base() {
this.vGrid = grid;
}
public override void Init(){
// creating a specific list for child category and editor rows
childRows = new ArrayList();
// creating a specific list for multi-editor rows
meRows = new ArrayList();
vGrid.BeginUpdate(); // preventing the grid from being updated
}
public override void Execute(DevExpress.XtraVerticalGrid.Rows.BaseRow row){
switch (row.XtraRowTypeID){
case 0: // category row is processed
// adding non top-level category row to specific list
if (row.ParentRow != null) childRows.Add(row);
// hiding row in the Customization Form
row.Visible = false;
break;
case 1: // editor row is processed
// adding non top-level editor row to specific list
if (row.ParentRow != null) childRows.Add(row);
// making row visible
if (!row.Visible) row.Visible = true;
break;
case 2: // multi-editor row is processed
// adding multi-editor row to specific list
meRows.Add(row);
break;
}
}
public override void Release(){
// splitting each multi-editor row from the obtained list into several editor rows
foreach (MultiEditorRow meRow in meRows) {
foreach (RowProperties rowItem in meRow.PropertiesCollection) {
// creating a new editor row for each row item
// of the processed multi-editor row
EditorRow eRow = new EditorRow();
// copying property settings from row item to the new editor row
rowItem.AssignTo(eRow.Properties);
// adding the newly created row to the grid collection of top-level rows
vGrid.Rows.Add(eRow);
}
// deleting the processed multi-editor row
if (meRow.ParentRow != null) meRow.ParentRow.ChildRows.Remove(meRow);
else meRow.Grid.Rows.Remove(meRow);
}
// moving each category or editor row from the obtained list
// to the collection of top-level grid rows
foreach (BaseRow row in childRows) {
row.Grid.MoveRow(row, row.Grid.Rows[0], true);
}
// unlocking the grid and causing its immediate repainting
vGrid.EndUpdate();
}
}
private void RestoreRowOrder() {
// creating an instance of the RowOperationRestoreOrder class
// and performing the operation on rows
RowOperationRestoreOrder restoreOrder = new RowOperationRestoreOrder(vGridControl1);
vGridControl1.RowsIterator.DoOperation(restoreOrder);
// creating an instance of a list used to automatically sort grid rows
// according to associated data fields
SortedList sortList = new SortedList();
// adding RowHandle and Name property values of all non-category rows
// to list as key-value pairs
foreach (BaseRow row in vGridControl1.Rows) {
if (row.Properties.RowHandle != -1)
sortList.Add(row.Properties.RowHandle, row.Name);
}
// setting the list capacity to the actual number of elements
sortList.TrimToSize();
// bringing order of grid rows in correspondence with the data fields order
for (int i = 0; i < sortList.Count; i++ ) {
vGridControl1.Rows[sortList.GetByIndex(i).ToString()].Index = i;
}
}
' Creating RowOperationRestoreOrder class
Public Class RowOperationRestoreOrder
Inherits RowOperation
Private VGrid As VGridControl
' reserving a list for category and editor rows processing
Private ChildRows As ArrayList
' reserving a list for multi-editor rows processing
Private MERows As ArrayList
Public Sub New(ByVal Grid As VGridControl)
Me.VGrid = Grid
End Sub
Public Overrides Sub Init()
' creating a specific list for child category and editor rows
ChildRows = New ArrayList()
' creating a specific list for multi-editor rows
MERows = New ArrayList()
' preventing the grid from being updated
VGrid.BeginUpdate()
End Sub
Public Overrides Sub Execute(ByVal Row As BaseRow)
Select Case Row.XtraRowTypeID
Case 0 ' category row is processed
' adding non top-level category row to specific list
If Not Row.ParentRow Is Nothing Then ChildRows.Add(Row)
' hiding row in the Customization Form
Row.Visible = False
Case 1 ' editor row is processed
' adding non top-level editor row to specific list
If (Not Row.ParentRow Is Nothing) Then ChildRows.Add(Row)
' making row visible
If Not Row.Visible Then Row.Visible = True
Case 2 ' multi-editor row is processed
' adding multi-editor row to specific list
MERows.Add(Row)
End Select
End Sub
Public Overrides Sub Release()
' splitting each multi-editor row from the obtained list into several editor rows
Dim MERow As MultiEditorRow
For Each MERow In MERows
Dim RowItem As RowProperties
For Each RowItem In MERow.PropertiesCollection
' creating a new editor row for each row item
' of the processed multi-editor row
Dim ERow As EditorRow = New EditorRow()
' copying property settings from row item to the new editor row
RowItem.AssignTo(ERow.Properties)
' adding the newly created row to the grid collection of top-level rows
VGrid.Rows.Add(ERow)
Next
' deleting the processed multi-editor row
If Not MERow.ParentRow Is Nothing Then
MERow.ParentRow.ChildRows.Remove(MERow)
Else
MERow.Grid.Rows.Remove(MERow)
End If
Next
' moving each category or editor row from the obtained list
' to the collection of top-level grid rows
Dim Row As BaseRow
For Each Row In ChildRows
Row.Grid.MoveRow(Row, Row.Grid.Rows(0), True)
Next
VGrid.EndUpdate() ' unlocking the grid and causing its immediate repainting
End Sub
End Class
Private Sub Button10_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button10.Click
'RestoreRowOrder()
' creating an instance of the RowOperationRestoreOrder class
' and performing the operation on rows
Dim RestoreOrder As New RowOperationRestoreOrder(VGridControl1)
VGridControl1.RowsIterator.DoOperation(RestoreOrder)
' creating an instance of a list used to automatically sort grid rows
' according to associated data fields
Dim SortList As New SortedList()
' adding RowHandle and Name property values of all non-category rows
' to list as key-value pairs
Dim Row As BaseRow
For Each Row In VGridControl1.Rows
If Row.Properties.RowHandle <> -1 Then
SortList.Add(Row.Properties.RowHandle, Row.Name)
End If
Next
' setting the list capacity to the actual number of elements
SortList.TrimToSize()
' bringing order of grid rows in correspondence with the data fields order
Dim I As Integer
For I = 0 To (SortList.Count - 1)
VGridControl1.Rows(SortList.GetByIndex(I).ToString()).Index = I
Next
End Sub
See Also