This is a migrated thread and some comments may be shown as answers.

LIGHTSWITCH display data from selected item in RowDetails

10 Answers 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 16 Jan 2013, 03:49 PM
Hi,
i try to use telerik controls in a lightswitch application.
I´ve made a simple Project with customers and orders.

Now, i try to display the orders in a row Detail.

If i place two user controls in the lightswitch Screen (one for the customers, one for the orders), everything works fine.But when i place the orders in the row Detail, no datas are displayed. I think, there is a Problem with binding. But i can´t find any solution.

Regards

Thomas



10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Jan 2013, 09:50 AM
Hello,

 You should have orders collection for your customer object if you want to place the orders grid in the customers grid row details. The DataContext of the row/row details is the customer.

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Thomas
Top achievements
Rank 1
answered on 17 Jan 2013, 09:54 AM
Hello Vlad,

i try this since 4 days and can´t find the right Syntax.

Can you give me a code sample?

Regards

Thomas
0
Vlad
Telerik team
answered on 17 Jan 2013, 09:57 AM
Hi,

 Here is it:

<telerik:RadGridView ItemsSource="{Binding Customers}">
  <telerik:RadGridView.RowDetailsTemplate>
     <DataTemplate>
         <telerik:RadGridView ItemsSource="{Binding Orders}" />
....

I would like to point once again that in this case you should have Orders collection property on your Customer object.

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Thomas
Top achievements
Rank 1
answered on 17 Jan 2013, 08:14 PM
Hi,

did you have tried this anytime with an entire lightswitch Project?

It´s not possible for me to make a running application. Also i can´t find any sample with these needs.

I can bind, whatever i want, but the Details grid is allways empty. I´ts a really simple Lightswitch application. A customer dataset with Name and a orderdata set with ordernumber. Also a relation between customer and order. By this relation, in Customer dataset exists a property named Ordercollection. But also by binding this property like in your sample, the Detail grid is empty.

My be, i´m to stupid to understand what i have to to. But after 4 days with trys and errors, it´s really frustrating.

Regards

Thomas
0
Thomas
Top achievements
Rank 1
answered on 17 Jan 2013, 08:32 PM
Additional Info:

Here is my code. Now, i get an error, if i expand the row.

System.Reflection.TargetInvocationException wurde nicht von Benutzercode behandelt.
  Message=Ein Aufrufziel hat einen Ausnahmefehler verursacht.
  StackTrace:
       bei System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       bei System.Delegate.DynamicInvokeImpl(Object[] args)
       bei System.Delegate.DynamicInvoke(Object[] args)
       bei SilverlightControl1xaml_2.BindingOperation_20_56(Object BindingState, Action ) in SilverlightClassLibrary1\SilverlightControl1.xaml:Zeile 1.
  InnerException: System.InvalidOperationException
       Message=Das Ausführen des Vorgangs für den aktuellen Thread ist ein ungültiger Vorgang.
       StackTrace:
            bei Microsoft.LightSwitch.Threading.DispatcherExtensions.VerifyAccess(IDispatcher dispatcher)
            bei Microsoft.LightSwitch.Framework.Internal.EntityCollection`3.GetEnumerator()
            bei Microsoft.LightSwitch.Framework.EntityCollection`1.System.Collections.IEnumerable.GetEnumerator()
            bei Telerik.Windows.Data.EnumerableExtensions.TryGetFirstElement(IEnumerable source, Object& firstElement)
            bei Telerik.Windows.Data.EnumerableExtensions.TryGetFirstElementType(IEnumerable source, Type& firstElementType)
            bei Telerik.Windows.Data.EnumerableExtensions.CastToFirstElementType(IEnumerable source)
            bei Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source, Type itemType)
            bei Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
            bei Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection, Type itemType)
            bei Telerik.Windows.Data.DataItemCollection.CreateAndSetCollectionView(IEnumerable source, Type type)
            bei Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source, Type type)
            bei Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass17.<Bind>b__16()
            bei Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
            bei Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
            bei Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
            bei Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
            bei Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            bei System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
            bei System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
            bei System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
            bei System.Windows.Data.BindingExpression.SendDataToTarget()
            bei System.Windows.Data.BindingExpression.SourceAcquired()
            bei System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass1.<BreakOnSingleType>b__0()
       InnerException:


<UserControl
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:SilverlightClassLibrary1" x:Class="SilverlightClassLibrary1.SilverlightControl1"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot" Background="White">
 
        <telerik:RadGridView ItemsSource="{Binding Screen.Customer}" HorizontalAlignment="Left" AutoGenerateColumns="True" VerticalAlignment="Top">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn />
            </telerik:RadGridView.Columns>
             
 
            <telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <telerik:RadGridView ItemsSource="{Binding OrderItem}" AutoGenerateColumns="False"/>
                </DataTemplate>
            </telerik:RadGridView.RowDetailsTemplate>
 
        </telerik:RadGridView>
 
    </Grid>
</UserControl>
0
Rossen Hristov
Telerik team
answered on 18 Jan 2013, 09:20 AM
Hello,

Let's look at your code:
<telerik:RadGridView ItemsSource="{Binding OrderItem}" AutoGenerateColumns="False"/>


I seriously doubt that property of the Customer class which contains the collection of Orders is called "OrderItem".

Does the Customer class have an IEnumerable property called OrderItem which contains all the Order for the Customer? Can you confirm this? Isn't it called Ordercollection as you mentioned in your previous post. If it is called Ordercollection, then why on earth are you binding the child grid to this non-existent OrderItem property?

Did you take a look at the source code that my colleague posted. Here it is again:

<telerik:RadGridView ItemsSource="{Binding Customers}">
   <telerik:RadGridView.RowDetailsTemplate>
      <DataTemplate>
          <telerik:RadGridView ItemsSource="{Binding Orders}" />

The thing in yellow should be the name of the IEnumerable property of your Customer class that contains the orders. You said that it is called Ordercollection. Hence the yellow thing should read Ordercollection and not OrderItem, which doubt that even exists on your Customer class. Is this so hard to understand?

Also, by setting AutoGenerateColumns to false, you tell the grid to not autogenerate the columns, because you will do it manually yourself. But you are not doing it anywhere. Hence, the grid is left without a single column. Why are you setting AutoGenerateColumns to false and then not defining any columns on the child grid. What do you expect to happen with this code.

Please, read RadGridView's online documentation before continuing with your project. I am sure that it will help avoiding this trial-and-error development approach and spare those days of frustration.

Thank you for your understanding.

Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Thomas
Top achievements
Rank 1
answered on 18 Jan 2013, 11:45 AM

 

Hello,

No, it´s not to hard to understand, but allways the question: Did you hav tried this anytime with a Lightswitch-Project?

If so, why i cant´t find any sample like this in the entrire web?

I have read the online documentaion many times and i also worked with your samples. In Silverlight, there´s no Problem for me to get what i want.. But not in Lightswitch.

You are right, i posted the wrong code with AutogeneretedColums="false".

I modified the code as followed to match your snippet and it´s the same Problem.

I have two tables in LIGHTSWITCH
1.) Customer
ID -> integer
Name -> string
Order -> Collection of OrderItem

2.) Order
ID -> integer
OrderNumber -> integer
Customer -> CustomerItem

First of all, if i use your snippets like 

<telerik:RadGridView ItemsSource="{Binding Customer">

no customers are shown. Like in your Lightswitch Documentation i must use 
 
<telerik:RadGridView ItemsSource="{Binding Screen.Customer}" >

With this line of Code, the customers are shown in a RadGridView.

In the row Details, i use 
 
<telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
 
                    <telerik:RadGridView ItemsSource="{Binding Order}" AutoGenerateColumns="False">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Nummer"
                                 DataMemberBinding="{Binding Nummer}" Width="100"/>
                        </telerik:RadGridView.Columns>

By using this, i get the Error posted in my last Topic if i open the Details. 

Btw: If i use this code in row Details as a seperate Elemt in my Lightswitch Screen, the data of order are displayed correctly.

<UserControl
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:SilverlightClassLibrary1" x:Class="SilverlightClassLibrary1.SilverlightControl1"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot" Background="White">
 
        <telerik:RadGridView ItemsSource="{Binding Screen.Customer}" HorizontalAlignment="Left" AutoGenerateColumns="False" VerticalAlignment="Top">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn />
                <telerik:GridViewDataColumn Header="Name"
                                 DataMemberBinding="{Binding Name}" Width="100"/>
                <telerik:GridViewDataColumn Header="Vorname"
                                 DataMemberBinding="{Binding Vorname}" Width="100"/>
            </telerik:RadGridView.Columns>
 
 
            <telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
 
                    <telerik:RadGridView ItemsSource="{Binding Order}" AutoGenerateColumns="False">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn Header="Nummer"
                                 DataMemberBinding="{Binding Nummer}" Width="100"/>
                        </telerik:RadGridView.Columns>
 
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.RowDetailsTemplate>
 
        </telerik:RadGridView>
 
    </Grid>
</UserControl>


 Regards

Thomas
 
 


0
Accepted
Rossen Hristov
Telerik team
answered on 18 Jan 2013, 11:59 AM
Hello,

It is quite possible that LightSwitch does not load the related Orders when it loads a customer. So they are simply empty. Maybe Microsoft can answer this.

We can guarantee that if there are orders in the customer object, the child grid will show them.

If no orders are loaded in the customer object for some reason, then this might be a LightSwitch limitation.

You can further research whether this is so on the LightSwitch forums or google for "LightSwitch master details".

I am afraid that we cannot be of any further assistance regarding this LightSwitch issue.

All the best,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Thomas
Top achievements
Rank 1
answered on 18 Jan 2013, 12:04 PM
Hello,

thanks for your time.
0
Thomas
Top achievements
Rank 1
answered on 20 Jan 2013, 01:57 PM
I think, i´ve found a solution.

It seems, the Object for order exists but it´s not possible to bind it directly.

From Karol Zadora:
but there is one important exception that is related to
LightSwitch threaading model. Without going into the details,
the basic limitation is that you cannot enumerate the children from the UI thread;
you have to do it from the screen logical thread

Karol has craeted a ValueConverter to resolve this Problem. You can find the complete thread here:

http://social.msdn.microsoft.com/Forums/en-US/lsextensibility/thread/bcdaa86f-459a-47d3-853a-3c5e56eb088a/

It works also for me in a row Detail.
Regards

Thomas



Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Thomas
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or