Password column in sfdatagrid

Hi, is it possible to create a password column in sfdatagrid?

I have done it before with the gridgroupingcontrol and you can set the passwordchar, but I can't find an equivalent in sfdatagrid.


6 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team November 17, 2021 05:10 PM UTC

Hi Rod Schmitzer

Thank you for contacting Syncfusion Support.

Currently, we are analyzing your requirement of “Password column in sfdatagrid” We will validate and update you the details on or before November 19, 2021.

We appreciate your patience until then.

Regards,
Vijayarasan S






VS Vijayarasan Sivanandham Syncfusion Team November 19, 2021 03:02 PM UTC

Hi Rod Schmitzer,

Thank you for your patience.

Your requirement can be achieved by overriding OnInitializeEditElement and OnRender method in GridTextBoxCellRenderer of SfDataGrid. Please refer the below code snippet, 

//here remove the default renderer for GridTextColumn 
this.sfDataGrid1.CellRenderers.Remove("TextBox"); 
//here added the custom renderer for GridTextColumn 
this.sfDataGrid1.CellRenderers.Add("TextBox", new GridTextBoxCellRendererExt()); 
 
public class GridTextBoxCellRendererExt : GridTextBoxCellRenderer 
{ 
        protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, TextBox uiElement) 
        { 
            //customize the based on your scenario 
            if (column.GridColumn.MappingName == "Password") 
            // Assign the asterisk to be the password character. 
                uiElement.PasswordChar = '*'; 
 
            base.OnInitializeEditElement(column, rowColumnIndex, uiElement); 
        } 
 
        protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) 
        { 
            //customize the based on your scenario 
            if (column.GridColumn.MappingName == "Password") 
            { 
                //customize the display text of password column 
                var countofchar = cellValue.Count(); 
 
                cellValue = string.Empty; 
 
                for (int i = 0; i < countofchar; i++) 
                //Assign the asterisk to be the password character display text of password column. 
                    cellValue += '*'; 
            } 
                
            base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); 
        } 
} 
 

For more information related to Customize Column Renderer, please refer the below user guide documentation link, 


Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 


Marked as answer

RS Rod Schmitzer November 22, 2021 01:35 AM UTC

That works great.

Thank you.




VS Vijayarasan Sivanandham Syncfusion Team November 22, 2021 05:29 AM UTC

Hi Rod Schmitzer,

Thanks for the update.

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,
Vijayarasan S



SA Saverio replied to Vijayarasan Sivanandham December 18, 2022 02:09 PM UTC

Hi,

why it is not already implemented directly a property/a value to identify a "password type" column, for example using the existing CellType or CellStyle properties of GridTextColumn class? Imho it seems absurd to have to implement code for such an elementary functionality...



VD Vasanthkumar Durairaj Syncfusion Team December 19, 2022 03:29 PM UTC

Hi Saverio,

Currently, SfDataGrid does not have direct support for the password column. By default, our SfDataGrid allows you to create your own column by overriding a predefined column type and to customize existing column renderers.

Find the UG link,

UG link - https://help.syncfusion.com/windowsforms/datagrid/columntypes#custom-column-support


Loader.
Up arrow icon