私はwpfアプリケーション用にtelrikRadGridViewを使用しています。グリッドをSQLデータベースにあるテーブルにバインドしたいと思います。かなり簡単だと思いましたが、あまり運が良くありません。SQLデータを取得し、適切に入力されているDataSetに保存しています。ただし、画面に表示されるのは、データが入力されていないテーブル列だけです。RadGridViewのXAMLは次のとおりです。
<telerik:RadGridView Name="Grid" Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Bottom"
AlternateRowBackground="AliceBlue" SelectionMode="Multiple"
AutoGenerateColumns="False" MinHeight="300" MinWidth="800" CanUserResizeColumns="True" CanUserResizeRows="True"
FilteringMode="FilterRow" IsFilteringAllowed="True" CanUserSortColumns="True" GridLinesVisibility="Both"
DataLoadMode="Asynchronous" >
<telerik:StyleManager.Theme>
<telerik:Windows8Theme/>
</telerik:StyleManager.Theme>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Width="40" Header="Add" DataMemberBinding="{Binding Add}" IsGroupable="False" IsFilterable="True" >
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Width="75" Header="Qty" IsGroupable="False" IsFilterable="True">
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Width="75" Header="ID" DataMemberBinding="{Binding ID}" IsGroupable="False" IsFilterable="True"/>
<telerik:GridViewDataColumn Width="200" Header="Description" DataMemberBinding="{Binding Description}" IsGroupable="False" IsFilterable="True"/>
<telerik:GridViewDataColumn Width="75" Header="Price" DataMemberBinding="{Binding Price}" IsGroupable="False" IsFilterable="True"/>
<telerik:GridViewDataColumn Width="75" Header="Min" DataMemberBinding="{Binding Min}" IsGroupable="False" IsFilterable="True"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
csコードでは、データセットを入力し、データコンテキストをグリッドに設定しています。
Grid.DataContext = ds.Tables[0].DefaultView;
私はまだWPFプログラミングに慣れていないので、ここでマイナーな何かが欠けているのか、それとも単に不可能なことをしようとしているのかわかりません。あなたが与えることができるどんな助けにもみんなありがとう。
編集:これは、グリッドのロード中のイミディエイトウィンドウからの出力です。
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'Object') from '' (type 'DataRowView'). BindingExpression:Path=[]; DataItem='DataRowView' (HashCode=30892613); target element is 'ValueSetter' (Name=''); target property is 'Value' (type 'Object') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: is neither a DataColumn nor a DataRelation for table Catalog.
at System.Data.DataRowView.get_Item(String property)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'
A first chance exception of type 'System.ArgumentException' occurred in System.ComponentModel.DataAnnotations.dll
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'Object') from '' (type 'DataRowView'). BindingExpression:Path=[]; DataItem='DataRowView' (HashCode=37343064); target element is 'ValueSetter' (Name=''); target property is 'Value' (type 'Object') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: is neither a DataColumn nor a DataRelation for table Catalog.
at System.Data.DataRowView.get_Item(String property)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level)
at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'
A first chance exception of type 'System.ArgumentException' occurred in System.ComponentModel.DataAnnotations.dll
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'Object') from '' (type 'DataRowView'). BindingExpression:Path=[]; DataItem='DataRowView' (HashCode=17870819); target element is 'ValueSetter' (Name=''); target property is 'Value' (type 'Object') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: is neither a DataColumn nor a DataRelation for table Catalog.
at System.Data.DataRowView.get_Item(String property)
--- End of inner exception stack trace ---