Sử dụng : datagridview để hiển thị bảng csdl, dùng datatable để nhận dữ liệu từ csdl nguồn.
+/Mục đích: khi bấm vào một cell thì cell đó sẽ chuyển từ DataGridViewTextBoxCell sang DataGridViewComboBoxCell cho phép tùy chọn dữ liệu.
+/Thực thi : quá trình thực thi tốt trừ với các cell có rowIndex=columnIndex thì sảy ra lỗi thông báo sau :
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore funct.
+/Code sử dụng :
// ham thuc hien viec chuyen sang combobox:
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == 2)
{
try
{
string query = "select * from FS";
DataGridViewComboBoxCell combo = new DataGridViewComboBoxCell();
ComboBind(combo, query);
combo.Value = combo.Items[1];
dataGridView1.Rows[e.RowIndex].Cells["GroupingTarget"] = combo;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
// ham thuc hien viec chuyen tro lai textbox:
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
try
{
DataGridViewTextBoxCell cel = new DataGridViewTextBoxCell();
cel.Value = dataGridView1.Rows[e.RowIndex].Cells["GroupingTarget"].Value;
dataGridView1.Rows[e.RowIndex].Cells["GroupingTarget"] = cel;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Bệnh này mình đã search rất nhiều nhưng vẫn chưa có cách gì. Mong mọi người giúp đỡ!
Khong ai co giai phap gi sao ? Ca cac bac MOD dau het rui`. hix hix