private void dgvTramTG_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (dgvTramTG.SelectedCells.Count > 0) { int id_dau = (int)dgvTramTG.SelectedCells[0].OwningRow.Cells["Tram_ID_Tram"].Value; //int id = (int)dgvTramTG.SelectedCells[0].OwningRow.Cells["ID_TramTG"].Value; BUS_Tram bustram = new BUS_Tram(); BUS_Tram bustramcuoi = new BUS_Tram(); Tram tram = bustram.getTramByID(id_dau); cbbTenTram.SelectedItem = tram; lbDiaDiem.Text = tram.DiaDiem; int index = -1; int i = 0; foreach (Tram item in cbbTenTram.Items) { if (item.IDTram == tram.IDTram) { index = i; break; } i++; } cbbTenTram.SelectedIndex = index; } } catch { } }
private void txtIDTuyenXe_TextChanged(object sender, EventArgs e) { try { if (dgvTuyenXe.SelectedCells.Count > 0) { int id_dau = (int)dgvTuyenXe.SelectedCells[0].OwningRow.Cells["ID_TramDau"].Value; int id_cuoi = (int)dgvTuyenXe.SelectedCells[0].OwningRow.Cells["ID_TramCuoi"].Value; int id = (int)dgvTuyenXe.SelectedCells[0].OwningRow.Cells["ID_Tuyen"].Value; BUS_Tram bustramdau = new BUS_Tram(); BUS_Tram bustramcuoi = new BUS_Tram(); Tram tramdau = bustramdau.getTramByID(id_dau); Tram tramcuoi = bustramcuoi.getTramByID(id_cuoi); cbbTramDau.SelectedItem = tramdau; cbbTramCuoi.SelectedItem = tramcuoi; lbDiaDiemDau.Text = tramdau.DiaDiem; lbDiaDiemCuoi.Text = tramcuoi.DiaDiem; int index1 = -1, index2 = -1; int i = 0, j = 0; foreach (Tram item in cbbTramDau.Items) { if (item.IDTram == tramdau.IDTram) { index1 = i; break; } i++; } foreach (Tram item in cbbTramCuoi.Items) { if (item.IDTram == tramcuoi.IDTram) { index2 = j; break; } j++; } cbbTramDau.SelectedIndex = index1; cbbTramCuoi.SelectedIndex = index2; ShowListTramTrungGian(id); } } catch { } }