我正在制作Windows窗体应用程序,其中使用了datagridview。
我希望当我在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);
                }
            }

最佳答案

void tb_TextChanged(object sender, EventArgs e)
{
    var enteredText = (sender as TextBox).Text
    ...
}

关于c# - 如何从datagridview textchanged事件中的当前单元格获取文本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21599154/

10-09 19:49