private void grdAirWayBillDetails_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { this.grdAirWayBillDetails.CommitEdit(); Dispatcher.BeginInvoke(new Action(() => { AddDetailRow(); }), DispatcherPriority.Background, null); } }So now I just need to work out how to detect when I am on the last row and column in the grid.
AirWayBillDetailEntity entity = this.AirWayBillDetail.NewEntity(new AirWayBillDetailDefaults(this.AirWayBill.Entity.awb_pk));>>
<DataGrid AutoGenerateColumns="False" Grid.Row="1" Grid.Column="3" >>>>> Height="Auto" >>>>> HorizontalAlignment="Stretch" >>>>> Margin="0" >>>>> Name="grdAirWayBillDetails" >>>>> VerticalAlignment="Stretch" >>>>> Width="Auto" >>>>> IsSynchronizedWithCurrentItem="True" >>>>> ItemsSource="{Binding Mode=default}" >>>>> SelectionMode="Single" >>>>> GridLinesVisibility="None" >>>>> HeadersVisibility="Column" >>>>> Grid.ColumnSpan="2" >>>>> >>>>> CanUserAddRows="False" >>>>> CanUserDeleteRows="False" >>>>> SelectionUnit="Cell" >>>>> Grid.RowSpan="4"> >>>>> <DataGrid.Resources> >>>>> <Style x:Key="AlignRight" TargetType="DataGridCell"> >>>>> <Setter Property="HorizontalAlignment" Value="Right" /> >>>>> >>>>> </Style> >>>>> <Style x:Key="AlignRightHeader" TargetType="DataGridColumnHeader"> >>>>> <Setter Property="HorizontalAlignment" Value="Right" /> >>>>> </Style> </DataGrid.Resources> >>>>> <DataGrid.Columns> >>>>> <DataGridComboBoxColumn Header="Charge Type" Width="2*" >>>>> DisplayMemberPath="cty_name" >>>>> SelectedValuePath="cty_pk" >>>>> SelectedValueBinding="{Binding awd_ctyfk, Mode=Default}"/> >>>>> >>>>> <DataGridTextColumn Header="Amount" Width="*" Binding="{Binding awd_amount, Mode=default}" >>>>> CellStyle="{StaticResource AlignRight}" >>>>> HeaderStyle="{StaticResource AlignRightHeader}"/> >>>>> </DataGrid.Columns> >>>>> </DataGrid>>>>>>
private void AddDetailRow() >>>>> { >>>>> AirWayBillDetailEntity entity = this.AirWayBillDetail.NewEntity(new AirWayBillDetailDefaults(this.AirWayBill.Entity.awb_pk)); >>>>> >>>>> // Select cell and begin edit >>>>> this.grdAirWayBillDetails.CommitEdit(); >>>>> >>>>> this.grdAirWayBillDetails.Focus(); >>>>> System.Windows.Controls.DataGridCellInfo cellInfo = new System.Windows.Controls.DataGridCellInfo(entity, this.grdAirWayBillDetails.Columns[0]); >>>>> this.grdAirWayBillDetails.SelectedCells.Clear(); >>>>> this.grdAirWayBillDetails.SelectedCells.Add(cellInfo); >>>>> this.grdAirWayBillDetails.CurrentCell = cellInfo; >>>>> this.grdAirWayBillDetails.BeginEdit(); >>>>> }>>>>>
void AirWayBillDetail_StateChange(mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e) >>>>> { >>>>> if (e.State == mmBusinessState.Retrieved) >>>>> { >>>>> // Store the Air WayBill Detail in the DataGrid's data context >>>>> this.grdAirWayBillDetails.DataContext = this.AirWayBillDetail.EntityList; >>>>> >>>>> // Hide the new item row place holder in the Air WayBill Detail DataGrid >>>>> ((IEditableCollectionView)CollectionViewSource.GetDefaultView(grdAirWayBillDetails.ItemsSource)).NewItemPlaceholderPosition = >>>>> NewItemPlaceholderPosition.None; >>>>> } >>>>> //this.ShowAirWayBillTotal(); >>>>> if (this.AirWayBillDetail.EntityList != null) >>>>> { >>>>> this.AirWayBillTotal = this.AirWayBillDetail.EntityList.Sum(x => x.awd_amount); >>>>> foreach (var c in this.AirWayBillDetail.EntityList) >>>>> { >>>>> c.PropertyChanged += CollectionItemChanged; >>>>> } >>>>> } >>>>> >>>>> }>>>>>
void CollectionItemChanged(object sender, PropertyChangedEventArgs e) >>>>> { >>>>> if (e.PropertyName == "awd_amount") >>>>> { >>>>> AirWayBillTotal = AirWayBillDetail.EntityList.Sum(x => x.awd_amount); >>>>> OnPropertyChanged("AirWayBillTotal"); >>>>> AddDetailRow(); >>>>> } >>>>> }>>>>>