Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect TreeView to .mdb Database in Visual Studio or Expression Blend
    text
    copied!<p>I'm a newbie to Visual Studio (2010) and Expression Studio (4).</p> <p>I have been trying to get a TreeView to connect to a .mdb database that I have connected in Visual Studio (using Silverlight Business Application) to show a Navigation Tree for the Name Properties in each table. I have 2 levels of hierarchy:</p> <p>(there are many more properties than shown but these are the only required)</p> <ol> <li>Root Level: <strong>Location Table</strong> [LocationName Property] </li> <li>First Level: <strong>Area Table</strong> [AreaName Property] [LocationID]</li> <li>Second Level: <strong>Inspection Table</strong> [InspectionName Property] [AreaID]</li> </ol> <p>I have tried many ways to connect and none seem to work - I am quite happy now with making a TreeView template with a connection to hierarchical Sample Data created in Expression Blend. Unfortunately, I can only seem to make a connection with the top level of my real database - so it only shows the names of the locations and won't expand any further.</p> <p>I have no idea what to do. The code I'm using is: (no code-behind)</p> <p><strong>Home.xaml</strong></p> <pre><code> &lt;riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Location, CreateList=true}" Height="0" LoadedData="locationDomainDataSource_LoadedData_1" Name="locationDomainDataSource" QueryName="GetLocationsQuery" Width="0"&gt; &lt;riaControls:DomainDataSource.DomainContext&gt; &lt;my:InspectDomainContext /&gt; &lt;/riaControls:DomainDataSource.DomainContext&gt; &lt;/riaControls:DomainDataSource&gt; &lt;sdk:TreeView Height="200" ItemsSource="{Binding ElementName=locationDomainDataSource, Path=Data}" Name="locationTreeView1" Width="200" &gt; &lt;sdk:TreeView.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="NavigationTreeResourceDictionary.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/sdk:TreeView.Resources&gt; &lt;sdk:TreeView.ItemTemplate&gt; &lt;StaticResource ResourceKey="RootLevel"/&gt; &lt;/sdk:TreeView.ItemTemplate&gt; &lt;/sdk:TreeView&gt; </code></pre> <p><strong>Navigation Tree Resource Dictionary</strong></p> <pre><code> &lt;common:HierarchicalDataTemplate x:Key="Level2"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Margin="5,0,3,0" FontStyle="Italic" Text="{Binding Path=Name}" /&gt; &lt;/StackPanel&gt; &lt;/common:HierarchicalDataTemplate&gt; &lt;common:HierarchicalDataTemplate x:Key="Level1" ItemsSource="{Binding Path=Inspections}" ItemTemplate="{StaticResource Level2}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Margin="5,0,3,0" Text="{Binding Path=Name}" /&gt; &lt;/StackPanel&gt; &lt;/common:HierarchicalDataTemplate&gt; &lt;common:HierarchicalDataTemplate x:Key="RootLevel" ItemsSource="{Binding Path=Areas}" ItemTemplate="{StaticResource Level1}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Margin="5,0,3,0" Text="{Binding Path=Name}" FontWeight="Bold" FontSize="12" /&gt; &lt;/StackPanel&gt; &lt;/common:HierarchicalDataTemplate&gt; </code></pre> <p><strong>Domain Service (c#) GetLocationsQuery</strong></p> <pre><code> public IQueryable&lt;Location&gt; GetLocations() { return this.ObjectContext.Locations.OrderBy(l=&gt;l.Name); } </code></pre> <p><strong>Is it perhaps something to do with the Query used? Should I be putting the information I need for the treeview in the GetLocationsQuery?</strong></p> <ul> <li>If so how do I put in the query to return a list of location names, child area names and child inspection names?</li> </ul> <p>Thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload