2017-09-08 6 views
0

の値を変更することができます。それはdoesntです。どうすればいい?このデータソースは、ボタン検索をクリックしてdatagridviewを入力するときのエンティティフレームワークです。は、どのように私は私がDataGridViewButtonColumn、セルの値の変更をクリックすることをDataGridViewのを持っているセルのDataGridView

private void dataGridViewBook_CellContentClick(object sender, DataGridViewCellEventArgs e) 
{ 
    var senderGrid = (DataGridView) sender; 
    if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && 
      e.RowIndex >= 0) 
    { 
     int countSelectedBook = Convert.ToInt32(dataGridViewBook.CurrentRow.Cells[5].Value); 
     countSelectedBook = countSelectedBook - 1; 
     dataGridViewBook.Rows[e.RowIndex].Cells[5].Value = countSelectedBook; 
    } 
} 
+0

それはあなたのグリッド内の行を表しViewModelにはINotifyPropertyChangedのを実装していないされていることを、可能ですか? –

答えて

1

問題:

あなたはViewModelにではなく、直接モデルにバインドしていないようです。あなたのモデルはINotifyPropertyChangedを実装していないので、あなたのGUIにプロパティ(その場合はCellValue)が更新されたときに通知される機会はありません。

MVVM Pattern 出典:https://en.wikipedia.org/wiki/File:MVVMPattern.png

あなたは上の画像のViewModelに-一部が欠けているように見えます。

ソリューション:

あなたはViewModelにはINotifyPropertyChangedの実装をのObservableCollectionにあなたのDataGridのItemSourceをバインドする必要があります。 ViewModelは、グリッド内の単一の行を表す必要があります。

さらに読書:https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel

さらに(INotifyPropertyChangedの)読み:https://msdn.microsoft.com/en-us/library/ms229614(v=vs.100).aspx

+0

ありがとう、私はこの問題を解決します。私はforeach()で1つずつデータをビンします。 –

関連する問題