Articles in this section

How to make the selections by record instead of by row?

In WinForms Grid, 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

\

Conclusion

I hope you enjoyed learning about how to make the selections by record instead of by row.

You can refer to our WinForms Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Grid example to understand how to create and manipulate data in the WinForms Grid.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid and other WinForms controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!


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