We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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?

Platform: WinForms |
Control: GridDataBoundGrid(Classic) |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon