Commit 8d4f730b kwwwvagaa

添加表格行自定义事件,用于自定义单元格

1 个父辈 44ae48b1
......@@ -12,5 +12,13 @@ namespace HZH_Controls.Controls
/// </summary>
/// <param name="obj">The object.</param>
void SetBindSource(object obj);
/// <summary>
/// 自定义事件传递,用于单元格向行中传递此事件
/// </summary>
event DataGridViewRowCustomEventHandler RowCustomEvent;
/// <summary>
/// 关联数据源
/// </summary>
object DataSource { get; }
}
}
......@@ -195,11 +195,20 @@ namespace HZH_Controls.Controls
if (item is IDataGridViewCustomCell)
{
IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
cell.RowCustomEvent += cell_RowCustomEvent;
cell.SetBindSource(DataSource);
}
}
}
void cell_RowCustomEvent(object sender, DataGridViewRowCustomEventArgs e)
{
if (RowCustomEvent != null)
{
RowCustomEvent(sender, e);
}
}
/// <summary>
/// Handles the MouseDown event of the Item control.
/// </summary>
......
......@@ -226,6 +226,7 @@ namespace HZH_Controls.Controls
if (item is IDataGridViewCustomCell)
{
IDataGridViewCustomCell cell = item as IDataGridViewCustomCell;
cell.RowCustomEvent += cell_RowCustomEvent;
cell.SetBindSource(DataSource);
}
}
......@@ -248,6 +249,12 @@ namespace HZH_Controls.Controls
}
}
void cell_RowCustomEvent(object sender, DataGridViewRowCustomEventArgs e)
{
if (RowCustomEvent != null)
RowCustomEvent(sender, e);
}
/// <summary>
/// Handles the MouseDown event of the Item control.
/// </summary>
......
......@@ -50,6 +50,7 @@
this.ucDataGridView1.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
this.ucDataGridView1.Size = new System.Drawing.Size(1090, 643);
this.ucDataGridView1.TabIndex = 5;
this.ucDataGridView1.RowCustomEvent += new HZH_Controls.Controls.DataGridViewRowCustomEventHandler(this.ucDataGridView1_RowCustomEvent);
//
// UCTestGridTableCustom
//
......
......@@ -44,5 +44,10 @@ namespace Test.UC
}
this.ucDataGridView1.DataSource = lstSource;
}
private void ucDataGridView1_RowCustomEvent(object sender, DataGridViewRowCustomEventArgs e)
{
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(), "你点击了:"+e.EventName);
}
}
}
......@@ -11,7 +11,15 @@ namespace Test.UC
{
public partial class UCTestGridTable_CustomCell : UserControl, HZH_Controls.Controls.IDataGridViewCustomCell
{
public event HZH_Controls.Controls.DataGridViewRowCustomEventHandler RowCustomEvent;
private TestGridModel m_object = null;
public object DataSource
{
get
{
return m_object;
}
}
public UCTestGridTable_CustomCell()
{
InitializeComponent();
......@@ -25,18 +33,32 @@ namespace Test.UC
private void ucBtnExt1_BtnClick(object sender, EventArgs e)
{
if (m_object != null)
if (RowCustomEvent != null)
{
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(),"修改:"+m_object.Name);
RowCustomEvent(this, new HZH_Controls.Controls.DataGridViewRowCustomEventArgs() { EventName = "Modify" });
}
//if (m_object != null)
//{
// HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(),"修改:"+m_object.Name);
//}
}
private void ucBtnExt2_BtnClick(object sender, EventArgs e)
{
if (m_object != null)
if (RowCustomEvent != null)
{
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(), "删除:" + m_object.Name);
RowCustomEvent(this, new HZH_Controls.Controls.DataGridViewRowCustomEventArgs() { EventName = "Delete" });
}
//if (m_object != null)
//{
// HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(), "删除:" + m_object.Name);
//}
}
}
}
......@@ -15,13 +15,24 @@ namespace Test.UC
{
InitializeComponent();
}
private TestGridModel m_object = null;
public object DataSource
{
get
{
return m_object;
}
}
public void SetBindSource(object obj)
{
if (obj is TestGridModel)
{
m_object = (TestGridModel)obj;
this.BackgroundImage = Properties.Resources.rowicon;
}
}
public event HZH_Controls.Controls.DataGridViewRowCustomEventHandler RowCustomEvent;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!