private void EditTrip_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { var chinhsua = dataGridView1.SelectedRows[0].DataBoundItem as Portion; var pf = new EditPortion(chinhsua); if (pf.ShowDialog() == DialogResult.OK) { portionBindingSource.ResetBindings(false); } } else { MessageBox.Show("Sorry, There Are Nothing To Edit \n You Can add some portions or Delete Agency ...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddTrip_Click(object sender, EventArgs e) { var pf = new EditPortion(); if (pf.ShowDialog() == DialogResult.OK) { agency.Portions.Add(pf.Portion); portionBindingSource.ResetBindings(false); if (dataGridView1.Rows.Count > 1) { var lastIdx = dataGridView1.Rows.Count - 1; dataGridView1.Rows[lastIdx].Selected = true; dataGridView1.FirstDisplayedScrollingRowIndex = lastIdx; } } }