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.
|
//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);
}
} |
That works great.
Thank you.
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...
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