我試圖將所有選定的行從一個數據網格複製到另一個。這裏是我一直在努力,到目前爲止做:將一個DataGrid的所有行復制到另一個
private void btnFeedbackSelectSupplier_Click(object sender, RoutedEventArgs e)
{
dgFeedbackAddCost.SelectAll();
IList list = dgFeedbackAddCost.SelectedItems as IList;
IEnumerable<ViewQuoteItemList> items = list.Cast<ViewQuoteItemList>();
//Example of how I want to access the data from the first datagrid and add it to
//the second one.
var item = (new ViewQuoteItemList
{
Item = items.Item,
Supplier = items.Cost
});
//Example
dgFeedbackSelectSupplier.Items.Add(item);
}
我的問題就在這裏:
var item = (new ViewQuoteItemList
{
Item = items.Item,
Supplier = items.Cost
});
而我得到的錯誤:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
現在我知道我做錯了,只是我不知道我怎麼能告訴你我想用代碼片段實現什麼。
所以我的問題是,我將如何能夠從items
演員訪問該數據並將其添加到我的ViewQuoteItemList
爲我的第二個數據網格?
你想要的是在'items'元素(而不是'items.Item'像'項目[0] .Item',我的意思嗎?)不它?你如何準確地得到'物品'?從'物品[0]'? '項[1]'? '項[2]'? 'items'中的每個'item'? – Ian
爲什麼不將第一個datagridview保存到數據表中,然後重新導入該表作爲第二個數據gridview的源? – Takarii
感謝您的評論伊恩。是的,我想獲得物品中的每件物品。 Foreach語句也許? – CareTaker22