我需要在DataGridView的同一列中,显示文本框或自定义控件.
我如何通过我的逻辑判断后动态的加载文本框和自定义控件到DataGridView的同一列中呢
谢谢啦.

解决方案 »

  1.   

    图片地址 http://hi.baidu.com/zj_zwl/album/item/d33756177773126c4890a74f.html
      

  2.   

            private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (dataGridView1.CurrentCell.ColumnIndex == 1 && dataGridView1.CurrentCell.RowIndex != -1)  //控制要处理的列
                {
                    if(你的逻辑判断1)
                    {
                            TextBox textBox=new TextBox ();
                             textBox.Location=e.Control.Location;
                             textBox.TextChanged += new EventHandler(textBox_TextChanged);  //订阅事件
                     }
                    if(你的逻辑判断2)
                    {
                            UserControl ctrl=new UserControl ();
                             ctrl.Location=e.Control.Location;
                             。。;//加入订阅自定义控件的事件
                     }
                }
            }
           void textBox_TextChanged(object sender, EventArgs e)
            {
                .............;//事件处理
            }
      

  3.   

    其实我要实现的效果如同:
    http://b211.photo.store.qq.com/psu?/98c9b9ec-ee7e-4580-9be6-d8c22343916d/xuDSKNjNvvWwFSvICP4uNMQQ.ao1MZwNqcL7KMJD.Wk!/b/YYbQ0X2hawAAYuBe030zawAA
      

  4.   

    楼主,这个问题需要自定义列来解决,下面的文章写的不错:http://hi.baidu.com/suralauto/blog/item/ef9eef89ef5feea30f244416.htmlhttp://blog.csdn.net/hulihui/article/details/3374134