我正在製作一個窗體應用程序,其中我使用了一個datagridview。 我想,當我寫在文本中datagridview的東西,不是一個消息框出現包含我寫的字符串.. ican't讓我在TextChanged事件文本..如何從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);
}
}
'字符串enteredText =((文本框)發送器)。文本;'是等價的。 – ThunderGr