在Winfrom里的datagrid能不能增加按钮列? 如题,这个要怎么增加按钮列呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是增加行还是增加列?如果是增加行那你可以在绑定的表中做Tb.DefaultView.AllowNew=AllowAdd;//是否可自动增加行 public delegate void DataViewButtonClickHandle(object sender, DataViewEventArgs args); /// <summary> /// DataViewButtonColumn 的摘要说明。 /// </summary> public class DataViewButtonColumn : DataViewColumn { public event DataViewButtonClickHandle DataViewButtonClick; private int curRow; private object component = null; public DataViewButtonColumn(int column) : base(column) { this.Control = new Button(); this.Button.Text = "\u2026"; this.Button.FlatStyle = FlatStyle.System; this.Button.Width = 20; this.Button.Click += new EventHandler(this.FireButtonClick); } public Button Button { get { return this.Control as Button; } } public override Control Control { set { if(value is Button) base.Control = value; } } protected override bool Commit(CurrencyManager DataSource, int RowNum) { this.HideControl(); if (this.inEdit) { try { if (!this.DataGridTableStyle.DataGrid.ReadOnly && component != null) { this.SetColumnValueAtRow(DataSource, RowNum, component); } } catch (Exception err) { throw err; } finally { this.EndEdit(); } } return true; } protected override void Edit(CurrencyManager Source, int Rownum, Rectangle Bounds, bool ReadOnly, string InstantText, bool CellIsVisible) { if(this.DataGridTableStyle.DataGrid.ReadOnly || this.ReadOnly) return; base.Edit(Source, Rownum, Bounds, ReadOnly, InstantText, CellIsVisible); curRow = Rownum; this.Control.Enabled = CellIsVisible; this.Control.Visible = true; this.Control.Height = Bounds.Height; this.Control.Top = Bounds.Top; this.Control.Left = Bounds.Left + (Bounds.Width - this.Control.Width); if (this.Control.Visible) this.DataGridTableStyle.DataGrid.Invalidate(Bounds); this.inEdit = true; } protected override int GetMinimumHeight() { return 20; } private void FireButtonClick(object sender, EventArgs e) { if (this.DataViewButtonClick != null) this.DataViewButtonClick(sender, new DataViewEventArgs(this, curRow)); } }看看哈 DataViewColumn 这个是从 DataGridColumnStyle 继承的 哇 看上去是挺麻烦的~~ 呵呵 谢谢pretty_soft() 网站的权限设置错误 正则表达式问题 c#winform项目卸载程序打包问题 winform知道文件路径(.pdf的文件),怎样打开它? 调用了COM组件,如何发布程序? 应用程序在没有装VS的机子上运行不成功,为什么? string CompareTo实现原理? 倾家荡产求"在RTF里表情图像与表情代码的互逆"文章中所指代码! 请问哪里有输入法的源代码或源程序? 问一个有关重复启动C#编写的exe和传参问题 请教DataSet 里有个image字段,保存为XML文件不能恢复image字段内容?? 新建一个.NET web应用程序 项目不成功?
如果是增加行
那你可以在绑定的表中做
Tb.DefaultView.AllowNew=AllowAdd;//是否可自动增加行
/// <summary>
/// DataViewButtonColumn 的摘要说明。
/// </summary>
public class DataViewButtonColumn : DataViewColumn
{
public event DataViewButtonClickHandle DataViewButtonClick;
private int curRow;
private object component = null; public DataViewButtonColumn(int column) : base(column)
{
this.Control = new Button();
this.Button.Text = "\u2026";
this.Button.FlatStyle = FlatStyle.System;
this.Button.Width = 20;
this.Button.Click += new EventHandler(this.FireButtonClick);
} public Button Button
{
get
{
return this.Control as Button;
}
} public override Control Control
{
set
{
if(value is Button)
base.Control = value;
}
} protected override bool Commit(CurrencyManager DataSource, int RowNum)
{
this.HideControl();
if (this.inEdit)
{
try
{
if (!this.DataGridTableStyle.DataGrid.ReadOnly && component != null)
{
this.SetColumnValueAtRow(DataSource, RowNum, component);
}
}
catch (Exception err)
{
throw err;
}
finally
{
this.EndEdit();
}
}
return true;
} protected override void Edit(CurrencyManager Source, int Rownum, Rectangle Bounds, bool ReadOnly, string InstantText, bool CellIsVisible)
{
if(this.DataGridTableStyle.DataGrid.ReadOnly || this.ReadOnly)
return;
base.Edit(Source, Rownum, Bounds, ReadOnly, InstantText, CellIsVisible);
curRow = Rownum;
this.Control.Enabled = CellIsVisible;
this.Control.Visible = true;
this.Control.Height = Bounds.Height;
this.Control.Top = Bounds.Top;
this.Control.Left = Bounds.Left + (Bounds.Width - this.Control.Width);
if (this.Control.Visible)
this.DataGridTableStyle.DataGrid.Invalidate(Bounds);
this.inEdit = true;
} protected override int GetMinimumHeight()
{
return 20;
} private void FireButtonClick(object sender, EventArgs e)
{
if (this.DataViewButtonClick != null)
this.DataViewButtonClick(sender, new DataViewEventArgs(this, curRow));
}
}
看看哈