private void gridControl2_Click_1(object sender, EventArgs e) { using (QL_DTDataContext BH1 = new QL_DTDataContext()) { cthd3DataGridView.Enabled = true; int rowHandle = gridView2.FocusedRowHandle; int col = cthd3DataGridView.Columns.Count; //if (cthd3DataGridView.Columns.Contains("coltensp")) //{ // cthd3DataGridView.Columns.Remove("coltensp"); // cthd3DataGridView.Columns.Remove("colsoluongct"); // cthd3DataGridView.Columns.Remove("coldongia"); // cthd3DataGridView.Columns.Remove("colgiamgia"); // cthd3DataGridView.Columns.Remove("colthanhtien"); // cthd3DataGridView.Columns.Remove("colmasp"); //} if (gridView2.SelectedRowsCount == 0) { gridControl2.Enabled = true; } else { string n = gridView2.GetRowCellValue(rowHandle, "MãHoáĐơn").ToString(); //var hienthi = from cthd in BH1.CHITIET_HDs // join hd in BH1.HOADONs on cthd.MAHD equals hd.MAHD // where hd.MAHD == n // select new // { // cthd.TENSANPHAM, // cthd.SOLUONG, // cthd.DONGIA, // cthd.GIAMGIA, // cthd.THANHTIEN // }; cthd3DataGridView.Rows.Clear(); cthd3DataGridView.DataSource = from cthd in BH1.CHITIET_HDs from hd in BH1.HOADONs where cthd.MAHD == hd.MAHD && hd.MAHD == n select new { Ten = cthd.TENSANPHAM, SL = cthd.SOLUONG, DG = cthd.DONGIA, Gia = cthd.GIAMGIA, ct = cthd.THANHTIEN }; txthoadon.Text = n; txttongtien.Text = string.Format("{0:n0}", Double.Parse(gridView2.GetRowCellValue(rowHandle, "TổngTiền").ToString())); DateTime date = DateTime.Parse(gridView2.GetRowCellValue(rowHandle, "NgàyLập").ToString()); string dateString = String.Format("{0:dd/MM/yyyy}", date); cmbngaylap.Text = dateString; //txtghichu.Text = ; txtkhachang.Text = gridView2.GetRowCellValue(rowHandle, "TênKháchHàng").ToString(); txtsdt.Text = gridView2.GetRowCellValue(rowHandle, "SốĐiệnThoại").ToString(); txtghichu.Text = gridView2.GetRowCellValue(rowHandle, "GhiChú").ToString(); } } }