Hello! Task - in the "Password" column, the table displays asterisks "********" instead of the real password. At the beginning of editing the password cell, the real password appears and can be edited. After editing the password, the data is saved, and asterisks appear again instead of the real password. How can this be organized? (C1FlexGrid Control ComponentOne, shared with DataGrid property and events) I use the following code

<Window x:Class="TurCC.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"> <c1:C1FlexGrid Name="gr_CertUsers" AllowSorting="True" AutoGenerateColumns="False" SelectionMode="Row" AllowDragging="None" GridLinesVisibility="All" AllowDrop="False" HeadersVisibility="Column" ItemsSource="{Binding Path=CertUsersCV}" SelectedItem="{Binding Path=SelectedCertUser, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CellEditEnded="gr_CertUsers_CellEditEnded" PrepareCellForEdit="gr_CertUsers_PrepareCellForEdit"> <c1:C1FlexGrid.Columns> <c1:Column ColumnName="UserLogin" Header="Логин" Binding="{Binding Login, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> </c1:Column> <c1:Column ColumnName="UserPassword" Header="Пароль" Binding="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> </c1:Column> </c1:C1FlexGrid.Columns> </c1:C1FlexGrid> </Window> private void gr_CertUsers_PrepareCellForEdit(object sender, CellEditEventArgs e) { // думаю, здесь можно вставить в ячейку реальный пароль } private void gr_CertUsers_CellEditEnded(object sender, CellEditEventArgs e) { //думаю, здесь можно вернуть звёздочки для ячейки, вместо реального пароля } 

I tried to change the cell text in the gr_CertUsers_PrepareCellForEdit function, but it did not work out. How to programmatically change the text at the time of the start of cell editing and at the time of the end of editing?

  • And what is a C1FlexGrid ? Looks like a control from some third-party library. - VladD
  • This is a ComponentOne control, has common properties and events with a DataGrid. Slightly complemented the xaml code in the description - Olejan
  • You have CertUsersCV as your data source. There passwords in what form? And how did you try to change the cell text? - Alexey
  • CertUsersCV - ObservableCollection <Users>. Users is a class that contains the UserLogin and Password properties of type string. I tried in the PrepareCellForEdit event to extract from the properties of the DataContext window, in which my ViewModel and the CertUsersCV collection lie. Changed the Password value in the collection, and changed the Password in the SelectedCertUser - the value in the collection has changed, but not in the cell - Olejan

2 answers 2

Your table is not "vkurse" changes that occur in its ItemsSource. Therefore, when you changed the password in CertUsersCV, the changes were not displayed. When linking data, if you want a timely update, after making changes, you must clearly indicate that the source has changed.

Although in your case, I would suggest implementing the following scheme: In the Users class, the Password property is divided by 2. That is, MaskedPassword and DeMaskedPassword. Where get'er MaskedPassword upon request returns DeMaskedPassword replacing all its characters with asterisks, and get'er DeMaskedPassword returns the password in its original form. Respectively set'er is only at DeMaskedPassword.

By trigger start editing password
change the Binding="{Binding Path=MaskedPassword to Binding="{Binding Path=DeMaskedPassword at <c1:Column ColumnName="UserPassword" Return the completion trigger.

A similar option can also be implemented not on triggers, but on events to which you subscribe (PrepareCellForEdit and CellEditEnded) In this case, the Users class should have some boolean field, depending on the value of which the getter returns either a masked password or demasked.

  • Implemented on events. I will give the code in the next answer - Olejan

Implemented our plans for PrepareCellForEdit and CellEditEnded events as follows

 private void gr_CertUsers_CellEditEnded(object sender, CellEditEventArgs e) { var vm = this.DataContext as TurCCVM; Column col = (sender as C1FlexGrid).Columns[e.Column] as Column; if (vm != null && vm.SelectedCertUser != null && col.ColumnName == "UserPassword") { vm.SelectedCertUser._bShowPswrd = false; } } private void gr_CertUsers_PrepareCellForEdit(object sender, CellEditEventArgs e) { var vm = this.DataContext as TurCCVM; Column col = (sender as C1FlexGrid).Columns[e.Column] as Column; if (vm != null && vm.SelectedCertUser != null && col.ColumnName == "UserPassword") { vm.SelectedCertUser._bShowPswrd = true; } } public class Users : ObservableObject { public string _UserName; public string _UserPswd; public bool _bShowPswrd = false; #region Properties public string Login { get { return _UserName; } set { _UserName = value; RaisePropertyChanged("Login"); } } public string Password { get { return _bShowPswrd ? _UserPswd : "*******"; } set { _UserPswd = value; RaisePropertyChanged("Password"); } } public bool ShowPswrd { get { return _bShowPswrd; } set { _bShowPswrd = value; RaisePropertyChanged("Password"); } } #endregion Properties }