I insert data to list and bind it to data-grid.
And when i try to reinsert data , the previous data is cleared .
I want the previous data not clear and new data add in list
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++;
}
Please advise me
Well you are creating a new instance of ltip every time you press the button. Try declaring ltip globaly like your count variable.
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++;
}
And the count variable isn't needed because it's include in the list. ltip.Count
精彩评论