これをできる限り明確にしようとしますが、間違った質問をしている可能性があることは十分承知しています. データセット内のデータテーブルにバインドする WPF (.NET 4.0) に datagrd があります。関連するコード ビハインド (ウィンドウの読み込み時に実行) は次のとおりです。
// create a connection to Top Trumps database
String cs = ConfigurationManager.ConnectionStrings["csTopTrumps"].ConnectionString;
SqlConnection cn = new SqlConnection(cs);
// create a new dataset
DataSet ds = new DataSet();
// open the connection (not strictly necessary, as the
// data adapter will do this when you use it anyway)
cn.Open();
// fill data table called Cards with contents of tblCard
SqlDataAdapter daCards = new SqlDataAdapter();
daCards.SelectCommand =
new SqlCommand("SELECT * FROM tblCard ORDER BY CardTitle", cn);
daCards.Fill(ds, "Cards");
// now set the data context for the entire window
this.DataContext = ds;
私のデータグリッド定義は次のように始まります:
<DataGrid ItemsSource="{Binding Tables[Cards]}"
それはすべてうまくいきます、そして私はそれを理解しています。データグリッドで行われた変更が基礎となるデータベースに更新されるように、データバインディングを双方向にしたいと考えています。これを行う方法の 1 つは、変更された行の値を取得し、Update メソッドで tableadapter を使用して、基になるデータベース (おそらく SelectedCellsChanged イベントなど) に加えられた変更を書き戻すことです。ただし、WPF のコード ビハインドでセル値を取得するのは難しいため、このようなアプローチは実装が困難です (WPF フレームワークを使用する必要があるため、これは間違った方法であると理解しています。助けてください) )。
では、どうすれば双方向のデータバインディングを設定して作業を行うことができますか? 次のようなデータグリッドプロパティの設定について言及している人を見てきました。
SelectedItem="{Binding Path=SelectedIndex,Mode=TwoWay}"
しかし、これをデータアダプターとデータセットで動作させる方法がわかりません。私が望んでいないのは、MVVMまたはモデルを含むソリューションです。これらを使用していないためです(はい、おそらく使用する必要があります)。また、監視可能なコレクション、コントロール階層を再帰的に検索して親を見つけるなど、複雑な C# コードの連なりを避けたいと考えています。
私は長い間検索してきましたが、私が求めているものは存在すると思います。存在しない場合は、存在しないと言ってください。時間を無駄にして申し訳ありません。