| List for WinForms Task-Based Help > Selecting a Row with a CheckBox |
In List for WinForms you can create a list that allows users to select and highlight an entire row of information. Clicking anywhere on that row will select and highlight the row. If you want users to have to click in a specific area a checkbox, for example to select and highlight a row or column. Follow these steps:

To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub C1List1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles C1List1.MouseClick
Dim row, col As Integer
Me.C1List1.CellContaining(e.X, e.Y, row, col)
If col <> -1 Then
If Me.C1List1.SelectedIndices.Contains(row) Then
Me.C1List1.SetSelected(row, False)
Else
Me.C1List1.SetSelected(row, True)
End If
End If
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void c1List1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
int row;
int col;
this.c1List1.CellContaining(e.X, e.Y, out row, out col);
if ((col != -1)) {
if (this.c1List1.SelectedIndices.Contains(row)) {
this.c1List1.SetSelected(row, false);
}
else {
this.c1List1.SetSelected(row, true);
}
}
|
|
Press the F5 key to run your application.
Notice that you can no longer select an entire row just by clicking anywhere on that row. To select and highlight the entire row, you must click the checkbox to the left of the row.