Articles in this section
Category / Section

In a Multirow record GDBG when the ListBoxSelectionMode is set to one, how do I make the selections move record by record instead of row by row?

1 min read

 

You can acheive this by handling the GridDataBoundGrid's QueryNextCurrentCellPosition, CurrentCellActivated, KeyUp events.In the QueryNextCurrentCellPosition, you can decide where the cell can be moved. In the CellActivated and KeyUp, you can clear the selection and select all the rows for that record.

C#

private void gridDataBoundGrid1_QueryNextCurrentCellPosition(object sender, Syncfusion.Windows.Forms.Grid.GridQueryNextCurrentCellPositionEventArgs e)

{

if(e.Direction == GridDirectionType.Down)

{

switch(e.RowIndex % 3)

{

case 1:

e.RowIndex = e.RowIndex +2;

break;

case 2:

e.RowIndex = e.RowIndex +1;

break;

case 0:

e.RowIndex = e.RowIndex;

break;

}

e.Handled = true;

e.Result = true;

}

}

private void gridDataBoundGrid1_CurrentCellActivated(object sender, System.EventArgs e)

{

//Clear the selection

this.gridDataBoundGrid1.Selections.Clear();

int top = this.gridDataBoundGrid1.CurrentCell.RowIndex;

while (top > this.gridDataBoundGrid1.Model.Rows.HeaderCount + 1&& top % 3 != 0)

top--;

int bot = this.gridDataBoundGrid1.CurrentCell.RowIndex;

while (bot < this.gridDataBoundGrid1.Model.RowCount && bot % 3 != 2)

bot++;

GridRangeInfo range = GridRangeInfo.Rows(top, bot);

this.gridDataBoundGrid1.Selections.SelectRange(range, true);

}

VB

Private Sub gridDataBoundGrid1_QueryNextCurrentCellPosition(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryNextCurrentCellPositionEventArgs) Handles gridDataBoundGrid1.QueryNextCurrentCellPosition

If e.Direction = GridDirectionType.Down Then

Select Case e.RowIndex Mod 3

Case 1

e.RowIndex = e.RowIndex + 2

Case 2

e.RowIndex = e.RowIndex + 1

Case 0

e.RowIndex = e.RowIndex

End Select

e.Handled = True

e.Result = True

End If

End Sub 'gridDataBoundGrid1_QueryNextCurrentCellPosition

Private Sub gridDataBoundGrid1_CurrentCellActivated(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridDataBoundGrid1.CurrentCellActivated

Me.gridDataBoundGrid1.Selections.Clear()

Dim top As Integer = Me.gridDataBoundGrid1.CurrentCell.RowIndex

While top > Me.gridDataBoundGrid1.Model.Rows.HeaderCount + 1 AndAlso top Mod 3 <> 0

top -= 1

End While

Dim bot As Integer = Me.gridDataBoundGrid1.CurrentCell.RowIndex

While bot < Me.gridDataBoundGrid1.Model.RowCount AndAlso bot Mod 3 <> 2

bot += 1

End While

Dim range As GridRangeInfo = GridRangeInfo.Rows(top, bot)

Me.gridDataBoundGrid1.Selections.SelectRange(range, True)

End Sub 'gridDataBoundGrid1_CurrentCellActivated

Here is the link with both CS and VB samples: http://websamples.syncfusion.com/samples/KB/Grid.Windows/GDBGMoveRecord/main.htm

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied