How to make GridControl behave like ListBox, selecting whole rows and not showing a currentcell?
Description
Need to make WinForms GridControl work like ListBox.
Solution
You need to do two things to make the GridControl work like ListBox. To achieve this requirement, you need to change the ListBoxSelectionMode and explicitly set the column index to 0 by using currentCellMoving and CurrentCellActivating events.
The following code examples are for changing ListBoxSelectionMode.
C#
// Changing the GridControlSelectionMode this.gridControl1.ListBoxSelectionMode = SelectionMode.One;
VB
' Changing the GridControlSelectionMode Me.gridControl1.ListBoxSelectionMode = SelectionMode.One
The following code example is for setting column index to 0.
C#
private void gridControl1_CurrentCellMoving(object sender, GridCurrentCellMovingEventArgs e) { e.ColIndex = 0; } private void gridControl1_CurrentCellActivating(object sender, GridCurrentCellActivatingEventArgs e) { e.ColIndex = 0; }
VB
Private Sub gridControl1_CurrentCellMoving(ByVal sender As Object, ByVal e As GridCurrentCellMovingEventArgs) e.ColIndex = 0 End Sub Private Sub gridControl1_CurrentCellActivating(ByVal sender As Object, ByVal e As GridCurrentCellActivatingEventArgs) e.ColIndex = 0 End Sub
The following screenshot is for GridControl without CurrentCell selection.
Figure 1: Selecting the row on clicking a cell without showing current cell
Sample:
C#: GridControl like ListBox CS
VB: GridControl like ListBox VB
I hope you enjoyed learning about how to make GridControl behave like ListBox, selecting whole rows and not showing a currentcell.
You can refer to our WinForms GridControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 GridControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!