2
真的,我有一個DataGrid和使用它的CellEditEnding事件。WPF DataGrid中,時刻關注電池如果e.Cancel =在CellEditEnding事件
默認情況下,在CellEditEnging事件,如果我取消了提交,它允許將光標移動到其他細胞或其他行。
我的查詢是有,如果我取消編輯任何其他方式,用戶不應該被允許,除非他糾正CellEditEnging事件進入一個移動的其他細胞或其他行。
MainWindow.xaml.cs Code
public MainWindow()
{
InitializeComponent();
List<Student> sList = new List<Student>();
sList.Add(new Student() { Name = "Amar" });
sList.Add(new Student() { Name = "Sagar" });
sList.Add(new Student() { Name = "Kiran" });
dg1.ItemsSource = sList;
dg1.CellEditEnding += Dg1_CellEditEnding;
}
private void Dg1_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
TextBox txtBox = e.EditingElement as TextBox;
if (txtBox != null && txtBox.Text.Equals("Amar"))
e.Cancel = true; //my requirement is,once i cancel ,focus should not move to other rows or other cells,it should be remain on this cell
}
}
public class Student : INotifyPropertyChanged
{
private string name;
public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged("Name");
}
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
:謝謝你的快速回復。獲取編譯錯誤,無法找到FindVisualChildByName – nk1