Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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# Windows窗体-按enter键添加行时出现问题_C#_.net_Windows_Forms_Algorithm - Fatal编程技术网

C# Windows窗体-按enter键添加行时出现问题

C# Windows窗体-按enter键添加行时出现问题,c#,.net,windows,forms,algorithm,C#,.net,Windows,Forms,Algorithm,我想做的是,当我在一个活动单元格中按enter键时,它应该会添加一个新行,但我不得不按两次,不知道如何对焦它 不能添加没有参数的新行 必须定义内容,请参见示例: //create DataTable DataTable Your_DT = new DataTable(); Your_DT.Columns.Add("first_Column", typeof(string)); Your_DT.Columns.Add("second_Column", typeof(string)); //ad

我想做的是,当我在一个活动单元格中按enter键时,它应该会添加一个新行,但我不得不按两次,不知道如何对焦它


不能添加没有参数的新行

必须定义内容,请参见示例:

//create DataTable
DataTable Your_DT = new DataTable();
Your_DT.Columns.Add("first_Column", typeof(string));
Your_DT.Columns.Add("second_Column", typeof(string));

//add new row
DataRow newRow = Your_DT.NewRow();
newRow["first_Column"] = "test";
newRow["second_Column"] = "test2";
Your_DT.Rows.Add(newRow);

//link DataTable to datagridview
dataGridView1.DataSource = Your_DT;

更清楚地说,我需要添加一个只有一次按下的新行。你的焦点在哪里?在文本框中按一下?是否要在Datagridview中添加空行?
//create DataTable
DataTable Your_DT = new DataTable();
Your_DT.Columns.Add("first_Column", typeof(string));
Your_DT.Columns.Add("second_Column", typeof(string));

//add new row
DataRow newRow = Your_DT.NewRow();
newRow["first_Column"] = "test";
newRow["second_Column"] = "test2";
Your_DT.Rows.Add(newRow);

//link DataTable to datagridview
dataGridView1.DataSource = Your_DT;