Problem: Ich möchte eingefügte Zeichen (AccountID) in Zelle von Datagridview, so dass ich entsprechenden Benutzernamen aus der Datenbank abrufen kann. Ich hatte in Problem stecken, dass auf Tastendruck-Ereignis von Datagridview, es wird nicht zuletzt Char einfügen. Wenn der Benutzername beispielsweise "John Snow" lautet, lautet seine ID = JN. Wenn ich 'J' in Datagridview Zelle schreibe und Wert auf Tastendruck bekomme, wird es "". Wenn ich weiter als 'JN' schreibe, wird es 'J'. In ähnlicher Weise wird es auf "JNE" "JN", also bekomme ich JohnSnow von der Datenbank. Kurz gesagt, es wird der vorherige Wert nicht vor kurzem eingefügt. Ich habe es Implement wieWerte von aktueller Spalte von DataGridView auf Tastendruck oder Keydown-Ereignis erhalten 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();
}
}
}
}
Vielen Dank. Es funktioniert. –
Sie sind willkommen – Naidu