winform如何把textbox作为列放到datagridview中

图片说明

如题和图中红框所示,winform中怎么实现这种输入框列啊,datagridviewtextboxcolumn列没有边框啊,怎么实现这种效果啊,急急急!

转:这个我刚好会,以前看了别人的博客学会的
先从工具箱拖一个textbox到窗体form1中.然后设置其为visible属性为false
在窗体加载中写
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Visible = false;
textBox1.Width = 0;
dataGridView1.Controls.Add(textBox1); //这句很重要的
}
datagridview1的CurrentCellChanged的事件中写
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
this.textBox1.Visible = false;
this.textBox1.Width = 0;
try
{
//前提是你的datagridview1一定要有数据呀
if (dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText == "你选中的单元格所在的列名")
{
//以下是把把textbox1的位置与datagridview1的单元格的位置一样,不过长宽均比单元格的短2
this.textBox1.Left = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true).Left;
this.textBox1.Top = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true).Top;
this.textBox1.Width = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true).Width-2;
this.textBox1.Height = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true).Height - 2;

                string str = Convert.ToString(this.dataGridView1.CurrentCell.Value);                                                this.textBox1.Text = str;//将单元格的值赋给文本框
                this.textBox1.Visible = true;
            }
        }
        catch
        {
        }
    }

在文本框的Validating事件中
private void textBox1_Validating(object sender, CancelEventArgs e)
{
this.dataGridView1.CurrentCell.Value = this.textBox1.Text;//如果文本框输入内容后,把其值赋给其对应的单元格
}

设置 textEdit
appearance -> BorderStyle->flat(或者其他样式)
即可显示边框