日期:2014-05-18  浏览次数:20655 次

怎样改写DataGridView,让他有以下功能?(高手请进)

怎样将DataGridView中的TextBoxColumn(假设为第二列)中加入一button,并且该button的右边和该列的右边对齐,该button的高度就是行高,button的宽度为该列的1/6,当我点击该button时弹出一Form,form右上方的顶点的left值与button的右边对齐,top为Button的Top加上Button的Height,当我点击Form上的按钮时,TextBoxColumn的内容为 "Testing   Click "

Thanks!

------解决方案--------------------
沙发,帮忙顶
------解决方案--------------------
button列的位置属性倒好设置,至于弹出form ,在DataList.ItemCommand 事件中用e.item.findcontrol(button)来引发javascript规定弹出form的位置应该也可以,至于form上点击按钮改变button的text要期待高手了
------解决方案--------------------
试一下如下的代码:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is DataGridViewTextBoxEditingControl)
{
DataGridViewTextBoxEditingControl textbox = e.Control as DataGridViewTextBoxEditingControl;
Button btn = new Button();
btn.Height = e.Control.Height;
btn.Width = e.Control.Width / 6;
btn.Top = 0;
btn.Left = e.Control.Width - btn.Width;
btn.Cursor = Cursors.Default;
btn.Click += new EventHandler(btn_Click);
textbox.Controls.Clear();
textbox.Controls.Add(btn);
}
}

void btn_Click(object sender, EventArgs e)
{
Form f = new Form();
f.StartPosition = FormStartPosition.Manual;
Button btn = sender as Button;
Rectangle bound = btn.Parent.RectangleToScreen(btn.Bounds);
f.Location = new Point(bound.Left, bound.Height + bound.Top);
f.Show(this);
}