Используя XAML listview / gridview с привязкой, я заполняю grid, используя запрос linq и код C #:
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();
Я заметил событие двойного щелчка для выбранных элементов.Каков синтаксис, позволяющий дважды щелкнуть строку и перенести эту строку в другую сетку под ней?
Суть в том, что я хотел бы иметь возможность добавить одну строку из одной сетки в другую сетку, дважды щелкнув выбранный элемент из одной сетки.
Редактировать: Код 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();
}