【发布时间】:2014-02-06 09:46:09
【问题描述】:
我正在制作一个使用 datagridview 的 Windows 窗体应用程序。 我希望当我在 datagridview 的文本框中写一些东西时,会出现一个包含我写的字符串的消息框。 无法在 textchanged 事件中获取我的文本..
所有东西都必须在 textchanged 事件中触发。 这是我的代码:-
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
TextBox tb = (TextBox)e.Control;
tb.TextChanged += new EventHandler(tb_TextChanged);
}
}
void tb_TextChanged(object sender, EventArgs e)
{
//listBox1.Visible = true;
//string firstChar = "";
//this.listBox1.Items.Clear();
//if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
string str = dataGridView1.CurrentRow.Cells["Column2"].Value.ToString();
if (str != "")
{
MessageBox.Show(str);
}
}
【问题讨论】:
标签: c# winforms datagridview