I use RowEditEnding event in datagrid to get updated row and update my database in return
private void OnUpdateOrInsertItem(object sender,DataGridRowEditEndingEventArgs e) { DataGridRow row1 = e.Row; int row_index = ((DataGrid)sender).ItemContainerGenerator.IndexFromContainer(row1); int numberOfColumns = ((DataGrid)sender).Columns.Count; DataGridCell RowColumn = ((DataGrid)sender).Columns[1].GetCellContent(row1).Parent as DataGridCell; string CellValue = ((TextBlock)RowColumn.Content).Text; MessageBox.Show(CellValue); }
but when I change cell which I print it in messageBox ,it returns an empty value on messageBox. I think the problem related to threads this is my xml code
<Grid> <DataGrid x:Name="datagrid1" AutoGenerateColumns="true" HorizontalAlignment="Left" Margin="0,55,0,0" VerticalAlignment="Top" Height="248" Width="672" RowEditEnding="OnUpdateOrInsertItem" PreviewKeyDown="OnDeleteItem"/> <Button Content="Show Database" HorizontalAlignment="Left" Margin="54,10,0,0" VerticalAlignment="Top" Width="98" RenderTransformOrigin="-0.193,-13.506" Height="29" Click="Button_Click_1"/> <ComboBox x:Name="comboBox1" SelectedIndex="0" HorizontalAlignment="Left" Margin="469,17,0,0" VerticalAlignment="Top" Width="120" Loaded="ComboBox_Loaded" SelectionChanged="ComboBox_SelectionChanged"/> </Grid>
how can I solve this problem or if there another way to get updated row in RowEditEnding event ?
No comments:
Post a Comment