//modify the carinfo private void ModifyCarinfoClick(object sender, RoutedEventArgs e) { DataManager ins = DataManager.createInstance(); Carinfo c = (Carinfo)this.CarList.SelectedItem; if (c == null) { System.Windows.MessageBox.Show("请选择后再修改", "提示", System.Windows.MessageBoxButton.OK); return; } addCar cw = new addCar(true, c); cw.Owner = this; if (cw.ShowDialog() ?? false) { ObservableCollection<Carinfo> cns = (ObservableCollection<Carinfo>)this.CarList.ItemsSource; int index = cns.IndexOf(c); cns.Remove(c); c = (Carinfo)cw.Thecar; this.DisplayCarID.Text = c.CarID; this.DisplayCarInsurance.Text = c.Insurancedate; this.DisplayCarPurchaseTime.Text = c.Purchasetime; this.DisplayCarRemark.Text = c.Remark; this.DisplayCarStatus.Text = c.Status; this.DisplayCarstyle.Text = c.Carstyle; this.DisplayLastCheck.Text = c.Latestchecktime; cns.Insert(index, c); //this.CitizenList.ItemsSource } }
//add car private void AddCarinfoClick(object sender, RoutedEventArgs e) { addCar cw = new addCar(false, new Carinfo()); cw.Owner = this; if (cw.ShowDialog() ?? false) { ObservableCollection<Carinfo> cns = (ObservableCollection<Carinfo>)this.CarList.ItemsSource; if (cns == null) { cns = new ObservableCollection<Carinfo>(); } Carinfo c = (Carinfo)cw.Thecar; cns.Add(c); this.CarList.ItemsSource = cns; } }