문제

I'm working with the telrik RadGridView for my wpf application. I want to bind the grid to a table I have in a SQL database. I thought it would be pretty straightforward, but I'm not having much luck with it. I'm getting the SQL data and storing it in a DataSet that is being filled properly. The only thing I'm getting on my screen though is the table columns with no data filling in. My XAML for the RadGridView is:

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

In the cs code, I'm filling the dataset and setting the datacontext to the grid with

      Grid.DataContext = ds.Tables[0].DefaultView;         

I'm still new to WPF programming, so I'm not sure if I'm missing something minor here or I'm trying to do something that simply isn't possible. Thank you guys for any help you can give.

Edit: Here is some output from the immediate window while loading the grid.

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

도움이 되었습니까?

해결책

After speaking with Telerik customer support for a bit on this, the issue was that
DataLoadMode = Asynchronous
doesn't work and had to be taken out. Also, I needed to set a height on my grid since I was using row virtualization.

다른 팁

Instead of
Grid.DataContext = ds.Tables[0].DefaultView;

do it like
Grid.ItemsSource = ds.Tables[0].DefaultView;

I mean it should be the ItemsSource property of the grid, not the DataContext. I am not sure about this but I think so.

Worked for me:

RadGridView.ValidatesOnDataErrors = "InEditMode"

Also see http://www.telerik.com/forums/argumentexception-when-using-icustomtypedescriptor

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top