二 自定义了委托和事件及事件的处理函数来处理固定行和固定列
定义一个委托
public delegate void RowDataBoundCellHandler(object sender, GridViewTableCell gvtc);
private static readonly object rowDataBoundCellEventKey = new object();
/// <summary>
/// RowDataBound事件中的所有单元格
/// </summary>
[Category("扩展")]
声明一个委托型的变量(声明事件RowDataBoundCell)
public event RowDataBoundCellHandler RowDataBoundCell
{
add { Events.AddHandler(rowDataBoundCellEventKey, value); }
remove { Events.RemoveHandler(rowDataBoundCellEventKey, value); }
}
/// <summary>
/// 触发RowDataBoundCell事件
/// </summary>
/// <param name="gvtc"></param>
建立一个虚方法,包含有触发事件的RowDataBoundCell(object sender, GridViewTableCell gvtc)
被外调用来触发事件.
protected virtual void OnRowDataBoundCell(GridViewTableCell gvtc)
{
RowDataBoundCellHandler handler = Events[rowDataBoundCellEventKey] as RowDataBoundCellHandler;
if (handler != null)
{
handler(this, gvtc);
}
}
将具体类的具体事件和具体的事件处理程序关联起来(初始化事件的处理)
this._sgv.RowDataBoundCell += new MyGridView.RowDataBoundCellHandler(_sgv_RowDataBoundCell);
void _sgv_RowDataBoundCell(object sender, GridViewTableCell gvtc)
在这个处理函数中程序根据新添加的复杂属性FixRowColumn的各项来对相应的表项添加属性,
这里的这个属性也就是样式
Helper.Common.SetAttribute(tc, "class", "yy_sgv_fixRow", AttributeValuePosition.Last, ' ');
Helper.Common.SetAttribute(tc, "class", "yy_sgv_fixCol", AttributeValuePosition.Last, ' ');