문제점 : DataGridview의 셀에 삽입 된 문자 (AccountID)를 가져와 데이터베이스에서 각각의 사용자 이름을 가져올 수 있습니다. 나는 datagridview의 keypress 이벤트에서 최근에 char를 삽입하지 못하는 문제에 봉착했습니다. 예를 들어, 사용자 이름이 'John Snow'이면 ID = JN입니다. datagridview 셀에 'J'를 쓰고 키 누르기에서 값을 얻으면 ""이됩니다. 나는 'JN'으로 더 쓸 때 'J'를 얻는다. 마찬가지로 'JNE'에서 'JN'을 얻습니다. 그러면 JohnSnow를 데이터베이스에서 가져옵니다. 즉, 최근에 삽입되지 않은 이전 값을 가져옵니다. 나는 다음과 같이keypress 또는 keydown 이벤트에서 DataGridView의 현재 열 값을 가져옵니다. C#
public DebitCredit()
{
InitializeComponent();
this.KeyPreview = true;
this.KeyPress += new KeyPressEventHandler(Control_KeyPress);
}
private void Control_KeyPress(object sender, KeyPressEventArgs e)
{
//Get the column and row position of the selected cell
int column = DGV_DEBIT_CREDIT.CurrentCellAddress.X;
int row = DGV_DEBIT_CREDIT.CurrentCellAddress.Y;
DataTable result=null;
if (column == 0)
{
string test = DGV_DEBIT_CREDIT[column, row].EditedFormattedValue.ToString();
result = getpro.SearchAccountByID(test);
if (result != null)
{
if (result.Rows.Count > 0)
{
DGV_DEBIT_CREDIT[column, row].Value = result.Rows[0][0].ToString();
DGV_DEBIT_CREDIT[column + 1, row].Value = result.Rows[0][1].ToString();
}
else
{
DGV_DEBIT_CREDIT[column, row].Value = "".ToString();
DGV_DEBIT_CREDIT[column + 1, row].Value = "".ToString();
}
}
}
}
고맙습니다. 그 일. –
당신은 환영합니다 – Naidu