Hello there,
We have a need to display personal information in redacted form.( ie SSN would display XXXXX1234, but we deal with other personal information and have worked out a component that will mask the data on simple controls.)
However, we use a lot of UltraWinGrid controls as well as UltraCombo controls with tabular displays. The data for these comes from DataSets and I don't really want to change the DataSet as some users will see full information and some will not. At the same time, if I redact the display, I don't want the ADO.NET GetChanges() method on the dataset to trigger something has changed so we need to stick to the display area on this. Here is the code I would LIKE to write, but cells don't have setters, see the final line where I would like to assign a value to row.Cells[_columnIndex].
public UltraGrid MaskedUltraGrid { get { return _grid; } set { _grid = value; if( MaskingEnable ) { var masking = new Mask(); UltraGridLayout layout = this._grid.DisplayLayout; UltraGridBand band = layout.Bands[_bandIndex]; UltraGridColumn column = band.Columns[_columnIndex]; foreach( var row in _grid.Rows ) { if( Convert.ToInt32( row.Cells["Type_ID"] ) == 1 || Convert.ToInt32(row.Cells["Type_ID"]) == 8 )
row.Cells[_columnIndex] = masker.MaskString( row.Cells[_columnIndex].ToString(), MaskingCharacter );
} } }
Does anyone have an alternative to using my masking control in a way that will permit it's use I prefer not to use the UltraGridMaskedEdit since it can't conditionally set the mask as in the above if condition?
Thanks in advance if anyone can point me the right way,
Kent
By the by...
UltraGridLayout layout = this._grid.DisplayLayout; UltraGridBand band = layout.Bands[_bandIndex]; UltraGridColumn column = band.Columns[_columnIndex];
are a red herring... I was searching through the components looking for something useful but are not required in above code.
Hi Kent,
This is going to be a bit trickier than that.
What I would do is hide the "real" column of data and then add an unbound column to display to the user. Then you handle the InitializeRow event of the grid and copy the "real" data into the unbound column and you can do whatever masking you want at that point.
If the data needs to be editable, you could also handle the BeforeRowUpdate event and copy the unbound cell data into the "real" cell so that it gets saved.
I realize that this solution isn't very abstract, since you will have to do the same thing for every column you want masked on all grids, combos, and dropdowns. But it's really the safest way to do it.
Another approach you could take it to modify the display using a CreationFilter. This would change the displayed text in the cell without affecting the underlying data. But there are a number of problems with this approach. For one thing, it will only affect the on-screen display. That means it will not affect copy & paste and it won't work if the cell goes into edit mode. It also won't affect exporting (although printing will work). Copying and exporting could be handled using events of the grid or the exporter like BeforeMultiCellOperation and ExportStarted. But there's no way to handle editing the cell as far as I can see. So this second approach might be better since it's a bit more encapsulated, but it requires more code and it won't work if the cell is editable.