Код: Выделить всё
Main.Designer.csКод: Выделить всё
private void InitializeComponent()
{
productGridView = new DataGridView();
productBindingSource = new BindingSource(components);
productBindingSource.DataSource = typeof(Product);
productGridView.DataSource = productBindingSource;
}
public DataGridView productGridView;
public BindingSource productBindingSource;
public void AddRows(int id, string name, float price, int instock, int min, int max)
{
this.productBindingSource.Add(new Product { ProductId = id, ProductName = name,
ProductPrice = price, InStock = instock, Max = max, Min = min });
this.productGridView.Refresh();
}
Код: Выделить всё
public void Save_Click(object sender, EventArgs e)
{
int _id = Convert.ToInt32(Id.Text);
string _name = ProductName.Text;
float _price = float.Parse(ProductPrice.Text);
int _qty = Convert.ToInt32(InStock.Text);
int _min = Convert.ToInt32(Min.Text);
int _max = Convert.ToInt32(Max.Text);
Main _main = new();
_main.AddRows(_id, _name, _price, _qty, _min, _max);
Close();
}
Код: Выделить всё
public class Product
{
public int ProductId { get; set; }
public string? ProductName { get; set; }
public double ProductPrice { get; set; }
public int InStock { get; set; }
public int Min { get; set; }
public int Max { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... swers-of-p
Мобильная версия