关于dataGridView里按钮的问题? 我想再dataGridView里加一列,这列里包括一个textbox和button,主要是我想点按钮时,弹出对话框来选商品,然后再将所选的商品名称填入textbox里面。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { dataGridView1.Rows.Add(); dataGridView1.Rows.Add(); dataGridView1.Rows.Add(); dataGridView1.Rows.Add(); dataGridView1.Rows.Add(); } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { //这里Column2是按钮类型,Column1是文本类型 if (e.ColumnIndex == Column2.Index) { form f = new form(); if (f.ShowDialog(this) == DialogResult.OK) { dataGridView1[Column1.Index, e.RowIndex].Value = f.GetValue; } } } } public class form : Form { TextBox tb1 = new TextBox(); TextBox tb2 = new TextBox(); Button b1 = new Button(); Button b2 = new Button(); public form() { this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Size = new Size(300, 300); this.Controls.Add(tb1); this.Controls.Add(tb2); this.Controls.Add(b1); this.Controls.Add(b2); tb1.Size = new Size(100, 21); tb1.Location = new Point(0, 0); tb1.Text = "文本1"; tb2.Size = new Size(100, 21); tb2.Location = new Point(0, 40); tb2.Text = "文本2"; b1.Size = new Size(50, 21); b1.Location = new Point(200, 0); b1.Text = "取文本1"; b2.Size = new Size(50, 21); b2.Location = new Point(200, 40); b2.Text = "取文本2"; b2.Click += new EventHandler(b2_Click); b1.Click += new EventHandler(b1_Click); } public string GetValue { get; set; } void b1_Click(object sender, EventArgs e) { GetValue = tb1.Text; this.DialogResult = DialogResult.OK; } void b2_Click(object sender, EventArgs e) { GetValue = tb2.Text; this.DialogResult = DialogResult.OK; } } IIS Quartz 失效的问题 关于mousemove事件的问题 开发工具换成VS2005,那以前2003开发的项目怎么办的大家.好多项目呀.一个个转换吗? VS2005的工具栏中,为什么没有owc11的控件呢? 一道有点难度的SQL问题 如何在部门textBox中显示的是部门的名称,而不是部门的代码 MagicLibrary中,上下停靠窗口大小的问题 c#对Excel对象的调用保存问题!急急急 免费下载《使用 Microsoft .NET 的企业解决方案模式》一书! 哭了,本来就不是很懂,卡在存储过程里的事务回滚了 屏蔽特殊字符 一个关于模拟表单提交的郁闷问题?
{
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add();
dataGridView1.Rows.Add();
dataGridView1.Rows.Add();
dataGridView1.Rows.Add();
dataGridView1.Rows.Add();
} private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//这里Column2是按钮类型,Column1是文本类型
if (e.ColumnIndex == Column2.Index)
{
form f = new form();
if (f.ShowDialog(this) == DialogResult.OK)
{
dataGridView1[Column1.Index, e.RowIndex].Value = f.GetValue;
}
}
}
} public class form : Form
{
TextBox tb1 = new TextBox();
TextBox tb2 = new TextBox();
Button b1 = new Button();
Button b2 = new Button(); public form()
{
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Size = new Size(300, 300);
this.Controls.Add(tb1);
this.Controls.Add(tb2);
this.Controls.Add(b1);
this.Controls.Add(b2);
tb1.Size = new Size(100, 21);
tb1.Location = new Point(0, 0);
tb1.Text = "文本1"; tb2.Size = new Size(100, 21);
tb2.Location = new Point(0, 40);
tb2.Text = "文本2"; b1.Size = new Size(50, 21);
b1.Location = new Point(200, 0);
b1.Text = "取文本1"; b2.Size = new Size(50, 21);
b2.Location = new Point(200, 40);
b2.Text = "取文本2"; b2.Click += new EventHandler(b2_Click);
b1.Click += new EventHandler(b1_Click);
} public string GetValue { get; set; } void b1_Click(object sender, EventArgs e)
{
GetValue = tb1.Text;
this.DialogResult = DialogResult.OK;
} void b2_Click(object sender, EventArgs e)
{
GetValue = tb2.Text;
this.DialogResult = DialogResult.OK;
}
}