ComponentOne FlexGrid for WinForms
Using Password Entries in C1FlexGrid
FlexGrid for WinForms Task-Based Help > Using Password Entries in C1FlexGrid

To show placeholder characters (*) in cells used for password entry, use the SetupEditor event.

  1. Create a column for passwords in the grid and set the draw mode:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.C1FlexGrid1.Cols(0).Width = Me.C1FlexGrid1.Rows(0).HeightDisplay
        Me.C1FlexGrid1.ShowCursor = True
        Me.C1FlexGrid1.Cols(1).Caption =((Me.C1FlexGrid1.Cols(1).Name) = "Password")
        Me.C1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw
    End Sub
    

    To write code in C#

    C#
    Copy Code
    {
        this.c1FlexGrid1.Cols[0].Width = this.c1FlexGrid1.Rows[0].HeightDisplay;
        this.c1FlexGrid1.ShowCursor = true;
        this.c1FlexGrid1.Cols[1].Caption = this.c1FlexGrid1.Cols[1].Name = "Password";
        this.c1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;
    }
    
  2. Add the following code for the SetupEditor event. This code will hide characters that are entered by the user.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Visual Basic
    Private Sub C1FlexGrid1_SetupEditor(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles C1FlexGrid1.SetupEditor
        Dim tb As TextBox = Me.C1FlexGrid1.Editor
        If Not (tb Is Nothing) Then
            If Me.C1FlexGrid1.Cols(e.Col).Name = "Password" Then
                tb.PasswordChar = "*"c
            Else
                tb.PasswordChar = CChar(0)
            End If
        End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1FlexGrid1_SetupEditor(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
    {
        TextBox tb = this.c1FlexGrid1.Editor as TextBox;
        if (tb != null)
        {
            if (this.c1FlexGrid1.Cols[e.Col].Name == "Password")
                tb.PasswordChar = '*';
            else
                tb.PasswordChar = (char)0;
        }
    }
    

This topic illustrates the following:

When the user enters a password in the Password column and presses ENTER, the text is automatically converted to asterisks.


See Also