Home Forums WinForms controls Xceed Grid for WinForms column of type password? Reply To: column of type password?

User (Old forums)
Member
Post count: 23064

Hi!

To make a cell showing its content as a masked password (i.e. “*******”), one possibility is:
 
DataRow dataRow;
// gridControl1 being the default grid name when dropped on a form, could be something else 
dataRow = this.gridControl1.DataRows.AddNew();
// WinTextBox is defined in Xceed.Editors so make you have a reference and a “using” directive
WinTextBox wtb = new WinTextBox();
// Add Xceed.Grid.Editors and Xceed.Grid.Viewers (as above)
// “Editors” being the name of the column containing this password field
dataRow.Cells[“Editors”].CellEditorManager = new TextEditor(wtb);
dataRow.Cells[“Editors”].CellViewerManager = new TextViewer(wtb);
dataRow.Cells[“Editors”].CellViewerManager.SettingControlAppearance += new CellViewerEventHandler(CellViewerManager_SettingControlAppearance);
 
with
 
void CellViewerManager_SettingControlAppearance(object sender, CellViewerEventArgs e)
{
  WinTextBox winTextBox = e.Control as WinTextBox;
  winTextBox.TextBoxArea.PasswordChar = ‘*’;
 
as the event handler to set the password character.
 
It could be a good thing to have another cell just next to this one to validate the password entered in the first cell, since the user won’t see what he is typing.
 
The code above is for a single row.  To apply this a password field cell to each row, simply address the column itself:
 
WinTextBox wtb = new WinTextBox();
this.gridControl1.Columns[“Password”].Title = “Password”;
this.gridControl1.Columns[“Password”].CellEditorManager = new TextEditor(wtb);
this.gridControl1.Columns[“Password”].CellViewerManager = new TextViewer(wtb);
this.gridControl1.Columns[“Password”].CellViewerManager.SettingControlAppearance += new CellViewerEventHandler(CellViewerManager_SettingControlAppearance);
 
keeping the same event handler as above:
 
void CellViewerManager_SettingControlAppearance(object sender, CellViewerEventArgs e)
{
  WinTextBox winTextBox = e.Control as WinTextBox;
  winTextBox.TextBoxArea.PasswordChar = ‘*’;

 

 

 

Imported from legacy forums. Posted by Ghislain (had 2989 views)