namespace GridControlDemo
{
class MyGridControl : GridControl
{
protected override BaseView CreateDefaultView()
{
return CreateView("MyGridView");
}
protected override void RegisterAvailableViewsCore(InfoCollection collection)
{
base.RegisterAvailableViewsCore(collection);
collection.Add(new MyGridViewInfoRegistrator());
}
} public class MyGridViewInfoRegistrator : GridInfoRegistrator
{
public override string ViewName { get { return "MyGridView"; } }
public override BaseView CreateView(GridControl grid)
{
return new MyGridView(grid as GridControl);
}
} public class MyGridView : GridView
{
/// <summary>
///函数
/// </summary>
/// <param name="ownerGrid"></param>
public MyGridView(GridControl ownerGrid) : base(ownerGrid) { } /// <summary>
/// 函数
/// </summary>
public MyGridView()
{ } /// <summary>
/// 初始化一些默认值
/// </summary>
public override void BeginInit()
{
base.BeginInit();
// 设置为多选
this.OptionsSelection.MultiSelect = true;
this.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
this.FocusedRowHandle = ;
this.Focus();
//显示筛选
this.OptionsView.ShowAutoFilterRow = true;
//隐藏提示
this.OptionsView.ShowGroupPanel = false;
//禁止编辑
this.OptionsBehavior.Editable = false;
this.OptionsView.EnableAppearanceEvenRow = false; //是否启用偶数行外观
this.OptionsView.EnableAppearanceOddRow = false; //是否启用奇数行外观
this.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never; //是否显示过滤面板 this.OptionsCustomization.AllowColumnMoving = false; //是否允许移动列
this.OptionsCustomization.AllowColumnResizing = false; //是否允许调整列宽
this.OptionsCustomization.AllowGroup = false; //是否允许分组
this.OptionsCustomization.AllowFilter = false; //是否允许过滤
this.OptionsCustomization.AllowSort = true; //是否允许排序
} public override void EndInit()
{
base.EndInit();
this.SelectionChanged += MyGridView_SelectionChanged;
} void MyGridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
int[] grvarry = this.GetSelectedRows();
if (grvarry.Length > )
{
/* for (int i = 0; i < grvarry.Length; i++)
{
GetDataRowList[i] = this.GetDataRow(grvarry[i]);
}*/
GetList = grvarry; }
else
{
GetDataRowInfo = this.GetFocusedDataRow();
}
//GetDataRowInfo = this.GetFocusedDataRow();
} /// <summary>
/// 获取用户选择行数据
/// </summary>
public DataRow GetDataRowInfo { get; set; }
/// <summary>
/// 返回选择行数组
/// </summary>
public DataRow[] GetDataRowList { get; set; }
/// <summary>
/// 返回用户选择行索引
/// </summary>
public int[] GetList { get; set; }
}
}
04-30 05:09