ListView DataBinding in UserControlHi, <div><br/></div> <div>I have two question with ListView DataBinding, </div> <div><br/></div> <div><strong><span style="text-decoration:underline">Note:</span></strong> This is WPF User Control</div> <div><br/></div> <div>1.Using the code below, I am unable to display data on the WPF form. <strong>Why this method not displying data??</strong></div> <div><br/></div> <div> <pre lang=x-xml>&lt;ListView Grid.Row=&quot;6&quot; Grid.ColumnSpan=&quot;2&quot; x:Name=&quot;lvProducts&quot; SelectionMode=&quot;Single&quot; ItemsSource=&quot;{Binding}&quot; DisplayMemberPath=&quot;ProductID&quot; IsSynchronizedWithCurrentItem=&quot;True&quot;&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Header=&quot;Product ID&quot; DisplayMemberBinding=&quot;{Binding Path =ProductID}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Name&quot; DisplayMemberBinding=&quot;{Binding Path =ProductName}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Description&quot; DisplayMemberBinding=&quot;{Binding Path =ProductDescription}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Price&quot; DisplayMemberBinding=&quot;{Binding Path =ProductPrice}&quot;&gt;&lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt;</pre> 2. Using code I am able display data on WPF form, but the Title are repating.., <strong>how to not repeate Titles ??</strong></div> <div><br/></div> <div> <pre lang=x-xml> &lt;ListView Name=&quot;lvProducts&quot; Grid.Row=&quot;6&quot; Grid.ColumnSpan=&quot;2&quot; VerticalContentAlignment=&quot;Stretch&quot; HorizontalContentAlignment=&quot;Stretch&quot; BorderThickness=&quot;2&quot; BorderBrush=&quot;Black&quot; Height=&quot;Auto&quot;&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot;&gt;ID&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot;&gt;Name&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;2&quot;&gt;Price&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;3&quot;&gt;Description&lt;/Label&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Text=&quot;{Binding Path=ProductID}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Text=&quot;{Binding Path=ProductName}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;2&quot; Text=&quot;{Binding Path=ProductPrice}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;3&quot; Text=&quot;{Binding Path=ProductDescription}&quot;&gt;&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt;</pre> <br/></div> <div><br/></div> <div>for both the ways I am using <strong>code behind </strong>below..</div> <div> <pre lang="x-c#"> private void UserControl1_Loaded(Object sender, RoutedEventArgs e) { ProductsDataContext db = new ProductsDataContext(); var query = from prod in db.Products select new { prod.ProductName, prod.ProductID, prod.ProductPrice, prod.ProductDescription }; this.lvProducts.ItemsSource = query; }</pre> </div> <div><span style="text-decoration:underline"><strong>Note:</strong></span> This is WPF User Control</div> <div><br/></div>© 2009 Microsoft Corporation. All rights reserved.Fri, 10 Jul 2009 09:02:32 Z6656e67f-f63d-442d-a991-2a85a697a7efhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#6656e67f-f63d-442d-a991-2a85a697a7efhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#6656e67f-f63d-442d-a991-2a85a697a7efVenkat Ganeshhttp://social.msdn.microsoft.com/Profile/en-US/?user=Venkat%20GaneshListView DataBinding in UserControlHi, <div><br/></div> <div>I have two question with ListView DataBinding, </div> <div><br/></div> <div><strong><span style="text-decoration:underline">Note:</span></strong> This is WPF User Control</div> <div><br/></div> <div>1.Using the code below, I am unable to display data on the WPF form. <strong>Why this method not displying data??</strong></div> <div><br/></div> <div> <pre lang=x-xml>&lt;ListView Grid.Row=&quot;6&quot; Grid.ColumnSpan=&quot;2&quot; x:Name=&quot;lvProducts&quot; SelectionMode=&quot;Single&quot; ItemsSource=&quot;{Binding}&quot; DisplayMemberPath=&quot;ProductID&quot; IsSynchronizedWithCurrentItem=&quot;True&quot;&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Header=&quot;Product ID&quot; DisplayMemberBinding=&quot;{Binding Path =ProductID}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Name&quot; DisplayMemberBinding=&quot;{Binding Path =ProductName}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Description&quot; DisplayMemberBinding=&quot;{Binding Path =ProductDescription}&quot;&gt;&lt;/GridViewColumn&gt; &lt;GridViewColumn Header=&quot;Product Price&quot; DisplayMemberBinding=&quot;{Binding Path =ProductPrice}&quot;&gt;&lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt;</pre> 2. Using code I am able display data on WPF form, but the Title are repating.., <strong>how to not repeate Titles ??</strong></div> <div><br/></div> <div> <pre lang=x-xml> &lt;ListView Name=&quot;lvProducts&quot; Grid.Row=&quot;6&quot; Grid.ColumnSpan=&quot;2&quot; VerticalContentAlignment=&quot;Stretch&quot; HorizontalContentAlignment=&quot;Stretch&quot; BorderThickness=&quot;2&quot; BorderBrush=&quot;Black&quot; Height=&quot;Auto&quot;&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot;&gt;ID&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot;&gt;Name&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;2&quot;&gt;Price&lt;/Label&gt; &lt;Label Grid.Row=&quot;0&quot; Grid.Column=&quot;3&quot;&gt;Description&lt;/Label&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Text=&quot;{Binding Path=ProductID}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Text=&quot;{Binding Path=ProductName}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;2&quot; Text=&quot;{Binding Path=ProductPrice}&quot;&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;3&quot; Text=&quot;{Binding Path=ProductDescription}&quot;&gt;&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt;</pre> <br/></div> <div><br/></div> <div>for both the ways I am using <strong>code behind </strong>below..</div> <div> <pre lang="x-c#"> private void UserControl1_Loaded(Object sender, RoutedEventArgs e) { ProductsDataContext db = new ProductsDataContext(); var query = from prod in db.Products select new { prod.ProductName, prod.ProductID, prod.ProductPrice, prod.ProductDescription }; this.lvProducts.ItemsSource = query; }</pre> </div> <div><span style="text-decoration:underline"><strong>Note:</strong></span> This is WPF User Control</div> <div><br/></div>Sat, 04 Jul 2009 17:47:28 Z2009-07-04T17:47:28Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#02a1c11c-8d95-4fb7-af6b-f1713c60fda7http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#02a1c11c-8d95-4fb7-af6b-f1713c60fda7Mark Salsberyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20SalsberyListView DataBinding in UserControlI think if you remove the &quot;<span style="color:red">DisplayMemberPath</span><span style="color:blue">=</span><span style="color:black">&quot;</span><span style="color:blue">ProductID</span><span style="color:black">&quot;</span>&quot; from the first version, your data should display correctly.<br/><br/>In the second version, you've put the titles in the item template, so every item gets title labels.<br/><br/><br/>Mark<br/><hr class="sig"> Mark Salsbery Microsoft MVP - Visual C++ Sat, 04 Jul 2009 20:47:45 Z2009-07-04T20:47:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#06063870-cbce-4a71-83a9-127a98f8d3cfhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6656e67f-f63d-442d-a991-2a85a697a7ef#06063870-cbce-4a71-83a9-127a98f8d3cfBruce.Zhouhttp://social.msdn.microsoft.com/Profile/en-US/?user=Bruce.ZhouListView DataBinding in UserControlHi VenKat,<br/> <br/> I performed a test with the first version of your code, the data can display correctly. Please check out if the linq to sql query returns the correct data on your side.<br/> <br/> Best regards,<br/> Bruce Zhou<hr class="sig">Please mark the replies as answers if they help and unmark if they don't.Fri, 10 Jul 2009 09:00:15 Z2009-07-10T09:00:15Z