private void getOrAddCompany(int index) { if (index < 0) { String name = Functions.TextFormat(companies.Text); if (name.Length == 0) { throw new Exception("Miasto nie może mieć pustej nazwy"); } companyNameList newCompany = new companyNameList() { Company = name }; context.company_name_list.Add(newCompany); context.SaveChanges(); companies.Items.Add(new Transport() { Name = newCompany.Company, Id = newCompany.Id }); companies.SelectedIndex = companies.Items.Count - 1; } }