Hi, hello to all that help. I'm learning WPF and making small testing, I am changing the value of a cell at the moment when I am editing another cell of the same row. The change in the cell is made, but the change in the datagrid is not observed.
What am I omitting so that the value that I am modifying is updated?
Thanks for the help.
I know that is about something textbox cell.
Please, help me to identify my mistake. Thanks a lot,
What I have tried:
This is my code(reduced):
public class clEmployee
{
public int employeeID { get; set; }
public string employeeNam { get; set; }
public Boolean isChanged { get; set; }
}
<datagrid
x:name="dgTesting"
margin="5,5,10,5"
autogeneratecolumns="False"
horizontalalignment="Stretch"
itemssource="{Binding myEmployees}"
verticalalignment="Stretch"
currentcellchanged="dgTesting_CurrentCellChanged"
celleditending="dgTesting_CellEditEnding"
previewkeydown="dgTesting_PreviewKeyDown"
height="500"
grid.column="0"
grid.row="1">
<datagrid.columns>
<datagridtextcolumn binding="{Binding Path=employeeID, Mode=TwoWay}" header="ID">
<datagridtextcolumn binding="{Binding Path=employeeName, Mode=TwoWay}" header="Names" width="700">
<datagridtextcolumn binding="{Binding Path=isChanged, Mode=TwoWay}" header="Changes">
public partial class wCatEmployees : Window
{
ObservableCollection<clemployee> myEmployees= new ObservableCollection<clemployee>();
public wCatEmployees()
{
InitializeComponent();
loadEployees();
}
private void loadEployees()
{
myEmployees = a.LoadEmployees();
dgTesting.ItemsSource = myEmployees;
}
private void dgTesting_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter || e.Key == Key.Return)
{
e.Handled = true;
dgTesting.CommitEdit();
}
}
private void dgTesting_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.EditAction != DataGridEditAction.Commit) { return; }
if (e.Column.SortMemberPath.Equals("employeeName"))
{
int Fi = dgTesting.Items.IndexOf(dgTesting.CurrentItem);
((clEmployee)dgTesting.Items[Fi]).isChanged = true;
this.dgTesting.Items.Refresh();
}
}
}
I don't know what more else to do.