2016-03-23 4 views
0

をRowEditEndingで空の値を取得のTextBlockはお返しに、私は更新された行を取得し、自分のデータベースを更新するために、DataGrid内RowEditEndingイベントを使用DataGrid内

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); 
    } 

が、私はメッセージボックスにそれを印刷するセルを変更したときに、それメッセージボックスに空の値を返します。 は、私がスレッド に関連する問題は、これは私がこの問題を解決することができるか、別の方法がある場合RowEditEndingイベント内の行を更新取得する方法を私のXMLコード

<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> 

あると思いますか?

答えて

0
  1. data binding(およびtemplating、ここではデータグリッドによって自動的に行われます)。更新された値は、そのイベントを使用する必要なしに、バインドされた(ビュー)モデルになります。
  2. ItemContainerGeneratorを使用しないでください。 UIアイテムにアクセスする必要がある場合は、関連するプロパティを基になるビューモデルにバインドします。
関連する問題