2011-03-26 58 views
0

使用XAML的ListView/GridView控件與結合使用我LINQ查詢和C#代碼填充網格:如何從listview/gridview獲取數據並填充另一個listview/gridview?

   AdventureWorkEntities awDatabase = new AdventureWorkEntities(); 
       var products = from p in awDatabase.Products 
           from i in awDatabase.ProductInventories 
           where p.ProductID == i.ProductID && p.ListPrice > 0 
           && p.Name.Contains(search.Text.Trim()) 
           select new 
           { 
            p.ListPrice, 
            p.Name, 
            p.ProductNumber, 
            p.DaysToManufacture, 
            i.Quantity 
           }; 

       IListSource query = (IListSource)products; 
       ProductsList.ItemsSource = query.GetList(); 

我注意到了選擇項的雙擊事件。能夠雙擊一行並將該行轉移到其下的另一個網格的語法是什麼?

jist是我希望能夠通過雙擊一個網格中的選定項目從一個網格添加一行到另一個網格。

編輯:XAML代碼:

<ListView Name="ProductsList" IsSynchronizedWithCurrentItem="True" DataContext="{Binding}" 
        Margin="6,76,6,220" Width="726" MouseDoubleClick="ProductsList_MouseDoubleClick"> 
       <ListView.View> 
        <GridView> 
         <GridView.Columns> 
          <GridViewColumn Width="85" Header="Product Number" 
              DisplayMemberBinding="{Binding Path=ProductNumber}"/> 
          <GridViewColumn Width="225" Header="Name" 
              DisplayMemberBinding="{Binding Path=Name}"/> 
          <GridViewColumn Width="135" Header="Days To Manufacture" 
               DisplayMemberBinding="{Binding Path=DaysToManufacture}"/> 
          <GridViewColumn Width="75" Header="Quantity" 
               DisplayMemberBinding="{Binding Path=Quantity}"/> 
          <GridViewColumn Width="75" Header="List Price" 
               DisplayMemberBinding="{Binding Path=ListPrice}"/> 
         </GridView.Columns> 
        </GridView> 
       </ListView.View> 
     </ListView> 

我的嘗試:

 private void ProductsList_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
    { 
     //code to place the contents of top grid to bottome grid 

     List<IQueryable> selectedContents = new List<IQueryable>(); 
     selectedContents.Add((IQueryable)ProductsList.SelectedValue); 
     IListSource query = (IListSource)selectedContents; 
     OrderContents.ItemsSource= query.GetList(); 
    } 
+0

您需要在此處提供更多數據。你說的是listview或grid,以及你在這裏綁定了什麼樣的數據?這是一張桌子嗎?清單?或任何自定義對象。 – 2011-03-26 00:37:29

+0

我已經顯示了我正在處理的代碼。我需要能夠從一個網格中選擇一行並將其放入與其完全相同的另一個網格中。 – asunrey 2011-03-26 01:57:13

回答

0

我缺乏語法知識阻止了我從f配置這一個班輪。

 private void ProductsList_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
    { 
     //moves items from top grid to bottom grid 
     OrderContents.Items.Add(ProductsList.SelectedValue); 
    } 
0

你需要做實體的觀察集合......而在雙擊事件得到所選實體從listView中添加選擇的實體到該Observable集合中,並將集合與第二個列表視圖綁定在一起...

+0

通過創建實體的Observable集合,你是指創建一個類的數據並將其放入一個集合中? – asunrey 2011-03-26 16:44:36

+0

我加了我的嘗試。 – asunrey 2011-03-26 16:55:39

相關問題