如何从datagridview textchanged事件中的当前单元格获取文本? [英] How to get the text from current cell in datagridview textchanged event?

查看:53
本文介绍了如何从datagridview textchanged事件中的当前单元格获取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Windows窗体应用程序,其中使用了datagridview。
i希望当我在datagridview的文本框中编写内容时,出现一个包含我编写的字符串的消息框。.
我无法在textchanged事件中获取文本。

i am making a windows form application in which i used a datagridview. i want that when i write something in textbox in datagridview,than a messagebox appears containing the string i wrote.. ican't get my text in textchanged event..

所有必须在textchanged事件中触发的东西。
这是我的代码:-

all thing must be fired in textchanged event.. here is my code:-

 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
    ...
}

这篇关于如何从datagridview textchanged事件中的当前单元格获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆