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.
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
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,
That works great.
Thank you.
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
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
- 6 Replies
- 4 Participants
- Marked answer
-
RS Rod Schmitzer
- Nov 17, 2021 01:33 AM UTC
- Dec 19, 2022 03:29 PM UTC