public void datatable() { this.Controls.Add(PreviousDataGridView); var data = new PocketMoney { Item = "Ciggarette", Money = 4500, Expenses = 4500 }; var adddata = new PocketMoney { Item = "CAN Coffee", Money = 2200, Expenses = data.Expenses + 2200, }; PocketMoneys.Add(data); PocketMoneys.Add(adddata); PreviousDataGridView.AutoGenerateColumns = false; if (PreviousDataGridView.AutoGenerateColumns == false) { PreviousDataGridView.DataSource = PocketMoneys; return; } }
private void AddButton_Click(object sender, EventArgs e) { PreviousDataGridView.AutoGenerateColumns = true; var ADD = new PocketMoney { Money = 0, Item = "", Expenses = 0 }; if (PreviousDataGridView.ColumnCount != 0) { PocketMoneys?.Add(ADD); } }