我将数据插入列表并将其绑定到数据网格。
当我尝试重新插入数据时,先前的数据被清除。
我希望之前的数据不清晰,新数据添加到列表中
int count = 0;
private void button_insert_Click(object sender, RoutedEventArgs e)
{
Table_infodetail_print tip = new Table_infodetail_print();
List<Table_infodetail_print> ltip = new List<Table_infodetail_print>();
tip.nation_code = nation_code;
tip.services_discription = comboBox_services.SelectedValue.ToString();
tip.additional_price = additional_price;
tip.lot_patient = lot_patient;
tip.price = price;
tip.tariff = tariff;
ltip.Insert(count, tip);
var select_details = from t in ltip
select t;
dataGrid_insert_services.ItemsSource = ltip;
count++;
}
请告诉我
答案 0 :(得分:0)
每次按下按钮,你都会创建一个新的ltip实例。尝试像计数变量一样声明ltip globaly。
int count = 0;
List<Table_infodetail_print> ltip = new List<Table_infodetail_print>();
private void button_insert_Click(object sender, RoutedEventArgs e)
{
Table_infodetail_print tip = new Table_infodetail_print();
tip.nation_code = nation_code;
tip.services_discription = comboBox_services.SelectedValue.ToString();
tip.additional_price = additional_price;
tip.lot_patient = lot_patient;
tip.price = price;
tip.tariff = tariff;
ltip.Insert(count, tip);
var select_details = from t in ltip
select t;
dataGrid_insert_services.ItemsSource = ltip;
count++;
}
并且不需要count变量,因为它包含在列表中。 ltip.Count