adding items to a list in c# wpf using form controls

  • Thread starter Thread starter MeToo_
  • Start date Start date
M

MeToo_

Guest
I have the below code that takes textbox data and addes an item to a list but after outputting the list to a data grid it appears that every time I add an item to the list the list gets cleared as I only get the latest item data on the data grid. What am I doing wrong?


namespace Training2.Windows
{
/// <summary>
/// Interaction logic for LotScan.xaml
/// </summary>
public partial class LotScan : Window
{
public LotScan()
{
InitializeComponent();

}

public class LotData
{
public string Lot;
public string Description { get; set; }
public int PO { get; set; }
public string MfgPart { get; set; }
}

private List<LotData> LoadCollectionData()
{
List<LotData> lot = new List<LotData>();
lot.Add(new LotData()
{
Lot = LotNo.Text,
Description = frmDescription.Text,
PO = int.Parse(frmPO.Text),
MfgPart = frmMfgPart.Text,
});
return lot;

}

private void Button_Click(object sender, RoutedEventArgs e)
{
gridLotData.ItemsSource = LoadCollectionData();

LotNo.Text = String.Empty;
frmMfgPart.Text = string.Empty;
frmDescription.Text = String.Empty;
frmMfgPart.Text = string.Empty;
frmPO.Text = string.Empty;
}



MeToo_

Continue reading...
 
Back
Top