ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Task-Based Help / Displaying the Current Column and Row
In This Topic
    Displaying the Current Column and Row
    In This Topic

    Using the Row and Col properties you can get the index of the currently selected cell's row and column. In the following example, you'll add two text boxes to your grid application, one that displays the currently selected row and another displaying the current column.

    Complete the following steps to display the current row and column:

    1. From the Visual Studio Toolbox add two Label and two TextBox controls.
    2. Resize and arrange the controls so that Label1 is next to TextBox1 and Label2 is next to TextBox2.
    3. In the Properties window, set the following properties:
      • Set Label1's Text property to "Row".
      • Set Label2's Text property to "Column".
    4. Add the following RowColChange event in the Code Editor:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub C1TrueDBGrid1_RowColChange(ByVal sender As System.Object, ByVal e As C1.Win.C1TrueDBGrid.RowColChangeEventArgs) Handles C1TrueDBGrid1.RowColChange
        Me.TextBox1.Text = C1TrueDBGrid1.Row
        Me.TextBox2.Text = C1TrueDBGrid1.Col
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1TrueDBGrid1_RowColChange(object sender, RowColChangeEventArgs e)
    {
        this.textBox1.Text = c1TrueDBGrid1.Row;
        this.textBox2.Text = c1TrueDBGrid1.Col;
    }
    

    This code will set the current row and column indexes to appear in the text boxes.

    What You've Accomplished

    Run your application and observe that the row and column text boxes display the row and column index for the selected grid cell:


    Choose a different cell and note that the text in the text boxes changes to display the currently selected cell's row and column index.