dataGridView dataGridView已经绑定好了,键盘点击“Enter”按钮后跳到另外的界面,如何编写后台代码呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e) { //判斷按下的鍵是否為Enter鍵 if (e.KeyValue == Keys.Enter) { //編寫業務代碼 MessageBox.Show("You press the enter key"); } }不知道事件找对没,你自己试试吧 父窗体 点击父窗体上的值 之后点击 enter 之后调到 子窗体namespace Datagridv{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string selecvalue = null; private void Form1_Load(object sender, EventArgs e) { List<Data> List = new List<Data>(); Data d = null; for (int i = 0; i < 5; i++) { d = new Data(); d.Str_id = i.ToString(); d.Str_id1 = i.ToString(); d.Str_id2 = i.ToString(); d.Str_id3 = i.ToString(); d.Str_id4 = i.ToString(); d.Str_id5 = i.ToString(); List.Add(d); } dataGridView1.DataSource = List; } private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { int a = e.KeyValue; // 值13 就代表 enter 键 if (a==13) { Form2 fr = new Form2(selecvalue); fr.ShowDialog(); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { selecvalue = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); } } public class Data { private string str_id; public string Str_id { get { return str_id; } set { str_id = value; } } private string str_id1; public string Str_id1 { get { return str_id1; } set { str_id1 = value; } } private string str_id2; public string Str_id2 { get { return str_id2; } set { str_id2 = value; } } private string str_id3; public string Str_id3 { get { return str_id3; } set { str_id3 = value; } } private string str_id4; public string Str_id4 { get { return str_id4; } set { str_id4 = value; } } private string str_id5; public string Str_id5 { get { return str_id5; } set { str_id5 = value; } } }}子窗体采用构造函数来传参namespace Datagridv{ public partial class Form2 : Form { string a = ""; public Form2(string ster) { InitializeComponent(); a = ster; } private void Form2_Load(object sender, EventArgs e) { label1.Text = a.ToString(); } }} private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyValue == Keys.Enter) { return base.ProcessDialogKey(Keys.Tab); } } 改一下 private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e) { //判斷按下的鍵是否為Enter鍵 if (e.KeyChar == (char)(13)) { //編寫業務代碼 MessageBox.Show("You press the enter key"); } } 分享一个配置文件管理工具,附源代码免积分下载,相信他能够减轻一点大家的工作 求一正则或解决方法 自己构造的DataTable怎么高效率的更新到数据库去? 如何让PictureBox在Dock为Fill的属性下显示滚动条 .NET windows应用程序 exe无法执行 帮介绍些,中文C#,NET文章好又多的地方吧. C#中 用POP3收邮件时,怎样判断有多少封新邮件和和这样判断用户名密码的正确性? ▲▲如何打印变量的地址▲▲????????急盼回复!!!!!谢谢!!!! c#中怎样设置全局变量。 C#调用C++ dll报错 C#简单计算器制作~~~·
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
//判斷按下的鍵是否為Enter鍵
if (e.KeyValue == Keys.Enter)
{
//編寫業務代碼
MessageBox.Show("You press the enter key");
}
}不知道事件找对没,你自己试试吧
namespace Datagridv
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string selecvalue = null;
private void Form1_Load(object sender, EventArgs e)
{
List<Data> List = new List<Data>();
Data d = null;
for (int i = 0; i < 5; i++)
{
d = new Data();
d.Str_id = i.ToString();
d.Str_id1 = i.ToString();
d.Str_id2 = i.ToString();
d.Str_id3 = i.ToString();
d.Str_id4 = i.ToString();
d.Str_id5 = i.ToString();
List.Add(d);
}
dataGridView1.DataSource = List;
} private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{ int a = e.KeyValue;
// 值13 就代表 enter 键
if (a==13)
{
Form2 fr = new Form2(selecvalue);
fr.ShowDialog();
}
} private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
selecvalue = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
}
public class Data
{
private string str_id; public string Str_id
{
get { return str_id; }
set { str_id = value; }
}
private string str_id1; public string Str_id1
{
get { return str_id1; }
set { str_id1 = value; }
}
private string str_id2; public string Str_id2
{
get { return str_id2; }
set { str_id2 = value; }
}
private string str_id3; public string Str_id3
{
get { return str_id3; }
set { str_id3 = value; }
}
private string str_id4; public string Str_id4
{
get { return str_id4; }
set { str_id4 = value; }
}
private string str_id5; public string Str_id5
{
get { return str_id5; }
set { str_id5 = value; }
}
}
}
子窗体采用构造函数来传参
namespace Datagridv
{
public partial class Form2 : Form
{
string a = "";
public Form2(string ster)
{
InitializeComponent();
a = ster;
} private void Form2_Load(object sender, EventArgs e)
{
label1.Text = a.ToString();
}
}
}
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyValue == Keys.Enter)
{
return base.ProcessDialogKey(Keys.Tab);
}
}
{
//判斷按下的鍵是否為Enter鍵
if (e.KeyChar == (char)(13))
{
//編寫業務代碼
MessageBox.Show("You press the enter key");
}
}