在下面的代碼中,我將項目從combobox
插入到datagrid
中。如何在列表中插入項目
private void cmbAddExtras_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
using (TruckServiceClient TSC = new TruckServiceClient())
{
var item = cmbAddExtras.SelectedItem as ExtraDisplayItems;
if (item != null)
{
var displayItem = new List<ExtraDisplayItems>
{
new ExtraDisplayItems
{
ItemId = item.ItemId,
ItemCode = item.ItemCode,
ItemDescription = item.ItemDescription,
ItemSellingPrice = item.ItemSellingPrice,
displayItems = item.displayItems //Always null?
}
};
dgAddExtras.Items.Add(item);
}
}
btnRemoveAllExtras.Visibility = Visibility.Visible;
}
我在下面我的課,在這裏我希望能夠訪問的項目在不同的方法,並得到總和總我ItemSellingPrice創建一個變量。
我的類:
public class ExtraDisplayItems
{
public List<ExtraDisplayItems> displayItems;
public int ItemId { get; set; }
public string ItemCode { get; set; }
public string ItemDescription { get; set; }
public double? ItemSellingPrice { get; set; }
}
現在我的問題是,在我插入的項目到DataGrid中的頂級方法,我displayItems
變量始終是出於某種原因空。是否有一些特殊的方法需要將這些項目加載到我班的displayItems
列表中?
你試過通過實例化displayItems嗎? – Karthik
@湍流 - 感謝您的回覆! :)我怎麼去做這件事?請你給我舉個例子嗎? – CareTaker22
Here you go 'public ExtraDisplayItems(){this.displayItems = new List();}' –
Karthik