ComponentOne List for WinForms
In This Topic
    Selecting a Row with a CheckBox
    In This Topic

    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:

    1. Start with the project you completed at the end of the Quick Start Step 2.
    2. From the Properties window, select the C1List control. Change the SelectionMode property from One to CheckBox. Your Form should look similar to this:
    3. From the Visual Studio menu, select View | Code.
    4. Add the following code to the Form_Load event:

      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);
      
                     }
      
             }
                                                      
      
    5. 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.