我正在爲我的wpf應用程序使用telrik RadGridView。我想將網格綁定到SQL數據庫中的表中。我認爲這很簡單,但我沒有太多運氣。我正在獲取SQL數據並將其存儲在正在正確填充的DataSet中。我得到我的屏幕上,雖然唯一的一點是,在沒有數據填充表列我對RadGridView XAML是:RadGridView數據綁定
<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代碼中,我填充DataSet和設置的datacontext與
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 ---
它也不能工作,我加入了一些從我的直接窗口輸出到我原來的帖子 – gdawgrancid 2013-02-10 18:36:29