Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中通过按键将datagridview转换为文本框#_C# - Fatal编程技术网

C# 在c中通过按键将datagridview转换为文本框#

C# 在c中通过按键将datagridview转换为文本框#,c#,C#,//我想通过按Enter键从datagridview填充文本框。我使用了此代码但失败。还有其他选择吗 Char ENTERKEY = (Char)Keys.Enter; private void dataGridView2_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == ENTERKEY) { int I = d

//我想通过按Enter键从datagridview填充文本框。我使用了此代码但失败。还有其他选择吗

    Char ENTERKEY = (Char)Keys.Enter;
          
    private void dataGridView2_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == ENTERKEY)
        {  
            int I = dataGridView2.CurrentRow.Index;
                          
            {
                dataGridView2.CurrentRow.Selected = true;
           
                cmbProducts.Text = dataGridView2.SelectedRows[0].Cells[0].Value.ToString();
                txtPrice.Text = dataGridView2.SelectedRows[0].Cells[3].Value.ToString();
                txtStock.Text = dataGridView2.SelectedRows[0].Cells[2].Value.ToString();
                txtsalerate.Text = dataGridView2.SelectedRows[0].Cells[3].Value.ToString();

            }

            
        }
           

    }

Enter
键的默认操作是将当前对象移动到下一行。如果使用
按键
事件,则保留此默认行为。如果要覆盖它,需要使用
KeyDown
事件并添加
e.SuppressKeyPress=truetxtPrice.Text=dataGridView2..CurrentRow.Cells[3].Value.ToString()。如果使用按键事件,
CurrentRow
将是下一个事件。