ComponentOne FlexGrid for WinForms
Hiding Characters Already Entered
FlexGrid for WinForms Task-Based Help > Using Password Entries in C1FlexGrid > Hiding Characters Already Entered

To hide the characters that have already been entered and do not need edited, use the OwnerDrawCell event.

  1. Add the following code for the OwnerDrawCell event. This code will hide the characters that have already been entered and do not need edited.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub C1FlexGrid1_OwnerDrawCell(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs) Handles C1FlexGrid1.OwnerDrawCell
        If e.Row >= Me.C1FlexGrid1.Rows.Fixed And Me.C1FlexGrid1.Cols(e.Col).Name = "Password" Then
            e.Text = New String("*"c, e.Text.Length)
        End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
    {
        if (e.Row >= this.c1FlexGrid1.Rows.Fixed && this.c1FlexGrid1.Cols[e.Col].Name == "Password")
        {
            e.Text = new string('*', e.Text.Length);
        }
    }
    
  2. Add the following code to the Form_Load event:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1FlexGrid1(1, 1) = "123456"
    

    To write code in C#

    C#
    Copy Code
    this.c1FlexGrid1[1,1] = "123456";
    

This topic illustrates the following:

Run the project again and notice the numbers are automatically loaded onto the form in the Password column as asterisks.