简体   繁体   English

如何在文本框C#中显示datagridview的值

[英]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 或键

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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