简体   繁体   中英

how to show value of datagridview in textbox C#

i have written the following codes but it shows the previous records in text boxes.

private void dataGridViewkala_KeyDown(object sender, KeyEventArgs e)
        {
            txtkalacode.Text = dataGridViewkala.CurrentRow.Cells[0].Value.ToString();
           txtkalaname.Text = dataGridViewkala.CurrentRow.Cells[1].Value.ToString();
            txtkqty.Text = dataGridViewkala.CurrentRow.Cells[2].Value.ToString();
            txtkalapoint.Text = dataGridViewkala.CurrentRow.Cells[3].Value.ToString();}

what is wrong in my codes, i try these codes too,

txtkalapoint.Text=dataGridViewkala.SelectedRows[0].Cells[3].Value.ToString();

when i press the arrow key in text boxes,it shows the previous records.

Key down happens before the actions taken, not after.. You could look at either the datagrid for when it changes rows, or, do it on the keypress. or Key up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM