1.功能:可以实现批量更改多列多行多单元格的值
2.选择方式:多列选择和多单元格选择,可以任选其中一个选择方式或两个方式同时用。
实现代码
代码
using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using System.Collections;
namespace MemberLevelSecurityDemo.Module
{
public partial class ViewController1 : ViewController
{
public ViewController1()
{
InitializeComponent();
RegisterActions(components);
}
private ArrayList selectedColumns;
private GridView gv = null;
private void SetCurrentColumnValue_Execute(object sender, ParametrizedActionExecuteEventArgs e)
{
if (e.ParameterCurrentValue == null) return;
gv.ClearSorting();
foreach (var col in selectedColumns)
{
for (int i = 0; i < gv.RowCount; i++)
{
gv.SetRowCellValue(i, col.ToString(), e.ParameterCurrentValue);
}
}
DevExpress.XtraGrid.Views.Base.GridCell[] selectedCells = gv.GetSelectedCells();
foreach (var item in selectedCells)
{
gv.SetRowCellValue(item.RowHandle, item.Column, e.ParameterCurrentValue);
}
// Save Changed
View.ObjectSpace.CommitChanges();
View.ObjectSpace.Refresh();
}
private void ViewController1_ViewControlsCreated(object sender, EventArgs e)
{
gv = ((View as ListView).Editor as GridListEditor).GridView;
gv.OptionsSelection.MultiSelect = true;
gv.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect;
selectedColumns = new ArrayList();
gv.MouseDown += gv_MouseDown;
}
void gv_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
var view = sender as GridView;
var info = view.CalcHitInfo(new Point(e.X, e.Y));
if (info.InColumn)
{
if (selectedColumns.IndexOf(info.Column.FieldName, 0, selectedColumns.Count) == -1)
{
info.Column.AppearanceCell.BackColor = Color.Gold;
selectedColumns.Add(info.Column.FieldName);
}
else
{
selectedColumns.Remove(info.Column.FieldName);
info.Column.AppearanceCell.BackColor = Color.Transparent;
}
}
}
}
}
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using System.Collections;
namespace MemberLevelSecurityDemo.Module
{
public partial class ViewController1 : ViewController
{
public ViewController1()
{
InitializeComponent();
RegisterActions(components);
}
private ArrayList selectedColumns;
private GridView gv = null;
private void SetCurrentColumnValue_Execute(object sender, ParametrizedActionExecuteEventArgs e)
{
if (e.ParameterCurrentValue == null) return;
gv.ClearSorting();
foreach (var col in selectedColumns)
{
for (int i = 0; i < gv.RowCount; i++)
{
gv.SetRowCellValue(i, col.ToString(), e.ParameterCurrentValue);
}
}
DevExpress.XtraGrid.Views.Base.GridCell[] selectedCells = gv.GetSelectedCells();
foreach (var item in selectedCells)
{
gv.SetRowCellValue(item.RowHandle, item.Column, e.ParameterCurrentValue);
}
// Save Changed
View.ObjectSpace.CommitChanges();
View.ObjectSpace.Refresh();
}
private void ViewController1_ViewControlsCreated(object sender, EventArgs e)
{
gv = ((View as ListView).Editor as GridListEditor).GridView;
gv.OptionsSelection.MultiSelect = true;
gv.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect;
selectedColumns = new ArrayList();
gv.MouseDown += gv_MouseDown;
}
void gv_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
var view = sender as GridView;
var info = view.CalcHitInfo(new Point(e.X, e.Y));
if (info.InColumn)
{
if (selectedColumns.IndexOf(info.Column.FieldName, 0, selectedColumns.Count) == -1)
{
info.Column.AppearanceCell.BackColor = Color.Gold;
selectedColumns.Add(info.Column.FieldName);
}
else
{
selectedColumns.Remove(info.Column.FieldName);
info.Column.AppearanceCell.BackColor = Color.Transparent;
}
}
}
}
}
代码
namespace MemberLevelSecurityDemo.Module
{
partial class ViewController1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.SetCurrentColumnValue = new DevExpress.ExpressApp.Actions.ParametrizedAction(this.components);
//
// SetCurrentColumnValue
//
this.SetCurrentColumnValue.Caption = "Set Current Column Value";
this.SetCurrentColumnValue.ConfirmationMessage = null;
this.SetCurrentColumnValue.Id = "SetCurrentColumnValue";
this.SetCurrentColumnValue.ImageName = null;
this.SetCurrentColumnValue.ShortCaption = null;
this.SetCurrentColumnValue.Shortcut = null;
this.SetCurrentColumnValue.Tag = null;
this.SetCurrentColumnValue.TargetObjectsCriteria = null;
this.SetCurrentColumnValue.TargetViewId = null;
this.SetCurrentColumnValue.ToolTip = null;
this.SetCurrentColumnValue.TypeOfView = null;
this.SetCurrentColumnValue.Execute += new DevExpress.ExpressApp.Actions.ParametrizedActionExecuteEventHandler(this.SetCurrentColumnValue_Execute);
//
// ViewController1
//
this.TargetViewType = DevExpress.ExpressApp.ViewType.ListView;
this.TypeOfView = typeof(DevExpress.ExpressApp.ListView);
this.ViewControlsCreated += new System.EventHandler(this.ViewController1_ViewControlsCreated);
}
#endregion
private DevExpress.ExpressApp.Actions.ParametrizedAction SetCurrentColumnValue;
}
}
{
partial class ViewController1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.SetCurrentColumnValue = new DevExpress.ExpressApp.Actions.ParametrizedAction(this.components);
//
// SetCurrentColumnValue
//
this.SetCurrentColumnValue.Caption = "Set Current Column Value";
this.SetCurrentColumnValue.ConfirmationMessage = null;
this.SetCurrentColumnValue.Id = "SetCurrentColumnValue";
this.SetCurrentColumnValue.ImageName = null;
this.SetCurrentColumnValue.ShortCaption = null;
this.SetCurrentColumnValue.Shortcut = null;
this.SetCurrentColumnValue.Tag = null;
this.SetCurrentColumnValue.TargetObjectsCriteria = null;
this.SetCurrentColumnValue.TargetViewId = null;
this.SetCurrentColumnValue.ToolTip = null;
this.SetCurrentColumnValue.TypeOfView = null;
this.SetCurrentColumnValue.Execute += new DevExpress.ExpressApp.Actions.ParametrizedActionExecuteEventHandler(this.SetCurrentColumnValue_Execute);
//
// ViewController1
//
this.TargetViewType = DevExpress.ExpressApp.ViewType.ListView;
this.TypeOfView = typeof(DevExpress.ExpressApp.ListView);
this.ViewControlsCreated += new System.EventHandler(this.ViewController1_ViewControlsCreated);
}
#endregion
private DevExpress.ExpressApp.Actions.ParametrizedAction SetCurrentColumnValue;
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/