在下面的代码中,我将项目从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