public class DevHelper
{
/// <summary>
/// 绑定ImageComBoBoxEdit下拉框数据
/// </summary>
/// <typeparam name="T">泛型类型</typeparam>
/// <param name="cmb">要绑定的ImageComBoBoxEdit空间</param>
/// <param name="lstSource">泛型List的数据源</param>
/// <param name="strTextFieldName">文本栏位名称</param>
/// <param name="strValueFieldName">值栏位名称</param>
/// <param name="strNotSelectedText">未选中时的文字显示</param>
/// <param name="blnInsertSelect">是否添加未选中文字选项</param>
public static void BindImageComboBoxEdit<T>
(ImageComboBoxEdit cmb,
List<T> lstSource,
string strTextFieldName,
string strValueFieldName,
string strNotSelectedText = "-请选择-",
object objNotSelectedValue = null,
bool blnInsertSelect = true)
{
try
{
cmb.Properties.Items.Clear();
foreach (var source in lstSource)
{
//Type Info
Type t = source.GetType();
//Get TextField value
PropertyInfo piText = t.GetProperty(strTextFieldName);
string strDescription = piText.GetValue(source, null).ToString();
//Get ValueField value
PropertyInfo piValue = t.GetProperty(strValueFieldName);
//object objValue = (piValue.GetValue(source)).ToString();
object objValue = ToTypeNew(piValue.PropertyType, piValue.GetValue(source, null));
//Add CoboItem
DevExpress.XtraEditors.Controls.ImageComboBoxItem item =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem();
item.Description = strDescription;
item.Value = objValue;
if (cmb.Properties.SmallImages != null)
{
var imageList = cmb.Properties.SmallImages as DevExpress.Utils.ImageCollection;
item.ImageIndex = imageList.Images.InnerImages.FindIndex(p => p.Name == item.Value.ToString());
}
cmb.Properties.Items.Add(item);
}
if (blnInsertSelect)
{
DevExpress.XtraEditors.Controls.ImageComboBoxItem itemNone =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem(strNotSelectedText, objNotSelectedValue);
cmb.Properties.Items.Insert(0, itemNone);
}
if (cmb.Properties.Items.Count > 0)
{
cmb.SelectedIndex = 0;
}
}
catch (Exception ex)
{
XShowError(ex.Message);
return;
}
}
/// <summary>
/// 绑定网格下拉框
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="repoIcb"></param>
/// <param name="lstSource"></param>
/// <param name="strTextFieldName"></param>
/// <param name="strValueFieldName"></param>
/// <param name="isReport"></param>
/// <param name="strNotSelectedText"></param>
/// <param name="objNotSelectedValue"></param>
/// <param name="blnInsertSelect"></param>
public static void BindRepImageComboBoxEdit_Old<T>
(RepositoryItemImageComboBox repoIcb,
List<T> lstSource,
string strTextFieldName,
string strValueFieldName,
bool isReport = false,
string strNotSelectedText = "",
object objNotSelectedValue = null,
bool blnInsertSelect = true)
{
try
{
repoIcb.Items.Clear();
foreach (var source in lstSource)
{
//Type Info
Type t = source.GetType();
//Get TextField value
PropertyInfo piText = t.GetProperty(strTextFieldName);
string strDescription = piText.GetValue(source, null).ToString();
//Get ValueField value
PropertyInfo piValue = t.GetProperty(strValueFieldName);
//object objValue = ReflectHelper.GetValue(source, strValueFieldName);
object objValue = ToTypeNew(piValue.PropertyType, piValue.GetValue(source, null));
//Add CoboItem
DevExpress.XtraEditors.Controls.ImageComboBoxItem item =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem();
item.Description = strDescription;
item.Value = objValue;
if (repoIcb.SmallImages != null)
{
var imageList = repoIcb.SmallImages as DevExpress.Utils.ImageCollection;
item.ImageIndex = imageList.Images.InnerImages.FindIndex(p => p.Name == item.Value.ToString());
}
repoIcb.Items.Add(item);
//repoIcb.Items.Add(source);
}
if (blnInsertSelect)
{
DevExpress.XtraEditors.Controls.ImageComboBoxItem itemNone =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem(strNotSelectedText, objNotSelectedValue);
repoIcb.Items.Insert(0, itemNone);
if (repoIcb.Items.Count > 0)
{
//设置默认选中
}
}
}
catch (Exception ex)
{
XShowError(ex.Message);
return;
}
}
/// <summary>
/// 绑定网格下拉框
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="repoIcb"></param>
/// <param name="lstSource"></param>
/// <param name="strTextFieldName"></param>
/// <param name="strValueFieldName"></param>
/// <param name="isReport"></param>
/// <param name="strNotSelectedText"></param>
/// <param name="objNotSelectedValue"></param>
/// <param name="blnInsertSelect"></param>
public static void BindRepImageComboBoxEdit<T>
(RepositoryItemImageComboBox repoIcb,
Enum lstSource,
string strTextFieldName,
string strValueFieldName,
bool isReport = false,
string strNotSelectedText = "",
object objNotSelectedValue = null,
bool blnInsertSelect = true)
{
try
{
repoIcb.Items.Clear();
var type = lstSource.GetType();
var enumName = Enum.GetNames(type);
foreach (var enum_Enity in enumName)
{
DevExpress.XtraEditors.Controls.ImageComboBoxItem item =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem();
var field = type.GetField(enum_Enity);
var objValue = field.GetValue(null);
// object objValue = ToTypeNew(piValue.PropertyType, piValue.GetValue(source, null));
var atts = field.GetCustomAttributes(typeof(DescriptionAttribute),false);
string Description = string.Empty;
if (atts != null && atts.Length > 0)
{
var att = ((DescriptionAttribute[])atts)[0];
Description = att.Description;
}
else
{
Description = enum_Enity;
}
item.Description = Description;
item.Value = objValue;
if (repoIcb.SmallImages != null)
{
var imageList = repoIcb.SmallImages as DevExpress.Utils.ImageCollection;
item.ImageIndex = imageList.Images.InnerImages.FindIndex(p => p.Name == item.Value.ToString());
}
repoIcb.Items.Add(item);
}
//var field = type.GetField(enumName);
//foreach (var source in lstSource)
//{
// //Type Info
// Type t = source.GetType();
// //Get TextField value
// PropertyInfo piText = t.GetProperty(strTextFieldName);
// string strDescription = piText.GetValue(source, null).ToString();
// //Get ValueField value
// PropertyInfo piValue = t.GetProperty(strValueFieldName);
// //object objValue = ReflectHelper.GetValue(source, strValueFieldName);
// object objValue = ToTypeNew(piValue.PropertyType, piValue.GetValue(source, null));
// //Add CoboItem
// //var type = source.GetType();
// //var enumName = Enum.GetName(type,source);
// //var field = type.GetField(enumName);
// //string strDescription=
// DevExpress.XtraEditors.Controls.ImageComboBoxItem item =
// new DevExpress.XtraEditors.Controls.ImageComboBoxItem();
// item.Description = strDescription;
// item.Value = objValue;
// if (repoIcb.SmallImages != null)
// {
// var imageList = repoIcb.SmallImages as DevExpress.Utils.ImageCollection;
// item.ImageIndex = imageList.Images.InnerImages.FindIndex(p => p.Name == item.Value.ToString());
// }
// repoIcb.Items.Add(item);
// //repoIcb.Items.Add(source);
//}
if (blnInsertSelect)
{
DevExpress.XtraEditors.Controls.ImageComboBoxItem itemNone =
new DevExpress.XtraEditors.Controls.ImageComboBoxItem(strNotSelectedText, objNotSelectedValue);
repoIcb.Items.Insert(0, itemNone);
if (repoIcb.Items.Count > 0)
{
//设置默认选中
}
}
}
catch (Exception ex)
{
XShowError(ex.Message);
return;
}
}
/// <summary>
/// 获取ImageComboBoxEdit对象选中项的值
/// </summary>
/// <param name="cmb">ImageComboBoxEdit对象</param>
/// <returns>返回选中项value字符串</returns>
public static string GetImageComboBoxSelectedValue(ImageComboBoxEdit cmb)
{
if (cmb == null || cmb.SelectedItem == null)
return string.Empty;
return (cmb.SelectedItem as DevExpress.XtraEditors.Controls.ImageComboBoxItem).Value.ToString();
}
/// <summary>
/// 弹出Dev错误提示框
/// </summary>
/// <param name="strErrorMsg"></param>
public static void XShowError(string strErrorMsg)
{
XtraMessageBox.Show(strErrorMsg, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
/// <summary>
/// 弹出Dev警告提示框
/// </summary>
/// <param name="strWarnMsg"></param>
public static void XShowWarn(string strWarnMsg)
{
XtraMessageBox.Show(strWarnMsg, "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
/// <summary>
/// 弹出Dev信息提示框
/// </summary>
/// <param name="strInfo"></param>
public static void XShowInfo(string strInfo)
{
XtraMessageBox.Show(strInfo, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 将指定value的字符串转换为指定的基本数据类型
/// </summary>
/// <param name="type">基本数据类型的Type类型信息</param>
/// <param name="value">待转换的字符串</param>
/// <returns>返回转换后的值</returns>
public static object ToTypeNew(Type type, object value)
{
object oRes = null;
try
{
if (value.GetType().FullName == type.FullName)
{
oRes = value;
}
else
{
//值类型
if (type.IsValueType)
{
if (value == null || value.ToString() == string.Empty)
{
oRes = Activator.CreateInstance(type);
}
else
{
oRes = System.ComponentModel.TypeDescriptor.GetConverter(type).ConvertFrom(value);
}
}
else
{
if (value == null || value.ToString() == string.Empty)
{
oRes = null;
}
else
{
oRes = System.ComponentModel.TypeDescriptor.GetConverter(type).ConvertFrom(value);
}
}
//oRes = System.ComponentModel.TypeDescriptor.GetConverter(type).ConvertFrom(value);
}
}
catch
{
oRes = value;
}
return oRes;
}
/// <summary>
/// 将指定的窗体绑定到tabControl
/// </summary>
/// <param name="frm">待绑定的窗体</param>
/// <param name="tabControl">要绑定到的tabControl控件</param>
/// <param name="strTabPageName">tabPage 的名称</param>
/// <param name="strTabPageText">tabPage 的显示标题</param>
public static void BindFormToTab(Form frm, XtraTabControl tabControl, string strTabPageName, string strTabPageText)
{
if (tabControl.TabPages.Where(x => x.Name == strTabPageName).Count() <= 0)
{
XtraTabPage page = new XtraTabPage();
page.Name = strTabPageName;
page.Text = strTabPageText;
//page.BackColor = Color.FromArgb(215, 228, 242);
frm.TopLevel = false;
frm.Parent = page;
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.Show();
tabControl.TabPages.Add(page);
tabControl.Refresh();
}
}
/// <summary>
/// 将指定的Form嵌入到已经存在的TabPage页签中
/// </summary>
/// <param name="frm"></param>
/// <param name="tabPage"></param>
public static void BindFormToTab(Form frm, XtraTabPage tabPage)
{
if (tabPage == null)
return;
tabPage.Controls.Clear();
frm.TopLevel = false;
frm.Parent = tabPage;
tabPage.Text = frm.Text;
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.Show();
}
/// <summary>
/// 保持行号
/// </summary>
/// <param name="dgv">datagridview控件</param>
/// <param name="rowIndex">行号索引</param>
public static void KeepSelectRow(GridView view, int rowIndex)
{
if (view == null)
return;
if (rowIndex >= 0)
{
if (rowIndex < view.DataRowCount)
{
view.FocusedRowHandle = rowIndex;
}
else
view.FocusedRowHandle = 0;
}
}
#region GridView相关
/// <summary>
/// 获取DevExpress的gridview当前选中行的数据对象
/// </summary>
/// <typeparam name="T">数据类型泛型名称</typeparam>
/// <param name="oGridView">Dev gridview对象</param>
/// <returns>返回当前选中行数据对象</returns>
public static T GetSelectedRowEntity<T>(GridView oGridView) where T : class
{
T oRes = default(T);
try
{
int rowIndex = oGridView.FocusedRowHandle;
if (rowIndex < 0)
rowIndex = 0;
object oSelectedRow = oGridView.GetRow(rowIndex);
if (oSelectedRow != null)
{
oRes = oSelectedRow as T;
}
}
catch
{
oRes = default(T);
}
return oRes;
}
/// <summary>
/// GridView CustomDrawRowIndicator事件处理函数,在Indicator处添加行号
/// </summary>
/// <param name="sender">GridView控件</param>
/// <param name="e">RowIndicatorCustomDrawEventArgs事件信息对象</param>
public static void GridView_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
if (e.Info.IsRowIndicator)
{
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
else if (e.RowHandle < 0 && e.RowHandle > -1000)
{
e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
e.Info.DisplayText = "G" + e.RowHandle.ToString();
}
}
}
/// <summary>
/// 网格无数据,显示提示信息
/// </summary>
/// <param name="strShowInfo">提示信息</param>
/// <param name="sender">GridView控件对象</param>
/// <param name="e">事件对象</param>
public static void GridView_CustomDrawEmptyForeground(string strShowInfo, object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
{
if (sender is GridView)
{
GridView gv = sender as GridView;
if (gv.RowCount == 0)
{
Font f = new Font("宋体", 9, FontStyle.Bold);
Rectangle r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);
e.Graphics.DrawString(strShowInfo, f, Brushes.Red, r);
}
}
}
/// <summary>
/// 将GridView选中的数据从其数据源中删除并刷新GridView网格
/// </summary>
/// <typeparam name="T">GridView选中行的数据类型</typeparam>
/// <param name="gv">GridView控件</param>
/// <param name="lstGridViewDataSource">GridView的数据源</param>
public static void DeleteSelectedRowFromGv<T>(GridView gv, List<T> lstGridViewDataSource) where T : class
{
if (gv != null && lstGridViewDataSource != null && lstGridViewDataSource.Count > 0)
{
if (gv.FocusedRowHandle < 0)
{
XShowError("请选择要删除的行");
return;
}
T oRowEntity = DevHelper.GetSelectedRowEntity<T>(gv);
if (oRowEntity != null)
{
bool blnRomoveRes = lstGridViewDataSource.Remove(oRowEntity);
if (blnRomoveRes)
{
gv.RefreshData();
}
}
}
}
#region
/// <summary>
/// GridView 数据行上移
/// </summary>
/// <typeparam name="T">GridView绑定数据类型泛型</typeparam>
/// <param name="gv">GridView对象</param>
public static void MoveUp(GridView gv)
{
try
{
if (gv.FocusedRowHandle - 1 < 0) return;
dynamic rowModel = gv.GetRow(gv.FocusedRowHandle);
if (rowModel == null)
{ return; }
dynamic tempField = rowModel.Clone();
dynamic upField = gv.GetRow(gv.FocusedRowHandle - 1);
dynamic fouceField = gv.GetRow(gv.FocusedRowHandle);
if (upField == null || fouceField == null)
return;
tempField.CopyValueFrom(upField);
upField.CopyValueFrom(fouceField);
fouceField.CopyValueFrom(tempField);
gv.CloseEditor();
gv.MovePrev();
gv.RefreshData();
}
catch (Exception ex)
{
XShowError("执行上移操作时发生系统异常!原因:" + ex.Message);
}
}
/// <summary>
/// GridView 数据行下移
/// </summary>
/// <typeparam name="T">GridView绑定数据类型泛型</typeparam>
/// <param name="gv">GridView对象</param>
public static void MoveDown(GridView gv)
{
try
{
if (gv.FocusedRowHandle + 1 == gv.RowCount) return;
dynamic rowModel = gv.GetRow(gv.FocusedRowHandle);
if (rowModel == null)
{ return; }
dynamic tempField = rowModel.Clone();
dynamic downField = gv.GetRow(gv.FocusedRowHandle + 1);
dynamic fouceField = gv.GetRow(gv.FocusedRowHandle);
if (downField == null || fouceField == null)
return;
tempField.CopyValueFrom(downField);
downField.CopyValueFrom(fouceField);
fouceField.CopyValueFrom(tempField);
gv.CloseEditor();
gv.MoveNext();
gv.RefreshData();
}
catch (Exception ex)
{
XShowError("执行下移操作时发生系统异常!原因:" + ex.Message);
}
}
/// <summary>
/// GridView 数据行移动到指定行
/// </summary>
/// <typeparam name="T">GridView绑定数据类型泛型</typeparam>
/// <param name="gv">GridView对象</param>
public static void MoveTo<T>(GridView gv, int pRowIndex)
{
try
{
if (gv.FocusedRowHandle < 0 || pRowIndex < 0 || pRowIndex > gv.RowCount - 1) return;
dynamic rowModel = gv.GetRow(gv.FocusedRowHandle);
dynamic tempField = rowModel.Clone();
dynamic upField = gv.GetRow(pRowIndex);
dynamic fouceField = gv.GetRow(gv.FocusedRowHandle);
tempField.CopyValueFrom(fouceField);
fouceField.CopyValueFrom(upField);
upField.CopyValueFrom(tempField);
gv.CloseEditor();
gv.MoveBy(pRowIndex);
gv.RefreshData();
}
catch (Exception ex)
{
XShowError("执行下移操作时发生系统异常!原因:" + ex.Message);
}
}
/// <summary>
/// 设置新行焦点
/// </summary>
/// <param name="gv"></param>
public static void SetNewRowFoucs(GridView gv)
{
if (gv.Columns.Count > 0)
{
gv.RefreshData();
gv.MoveLast();
gv.FocusedColumn = gv.Columns[0];
gv.FocusedRowHandle = gv.RowCount - 1;
gv.ShowEditor();
}
}
/// <summary>
/// 删除网格中的行
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="gv"></param>
public static void DelRow(GridView gv)
{
gv.DeleteSelectedRows();
gv.SelectRow(gv.FocusedRowHandle);
}
#endregion
#endregion
public static void BindColumns(
DevExpress.XtraGrid.Views.Grid.GridView view,
List<ColumnInfo> columns
)
{
if (view == null) return;
view.CustomDrawRowIndicator -= GridView_CustomDrawRowIndicator;
view.CustomDrawRowIndicator += GridView_CustomDrawRowIndicator;
view.OptionsView.ShowGroupPanel = false;
//view.OptionsBehavior.EditorShowMode = EditorShowMode.Default;
//view.Appearance.VertLine.BackColor = SystemColors.ActiveCaption;
//view.Appearance.HorzLine.BackColor = SystemColors.ActiveCaption;
//view.Appearance.VertLine.Options.UseBackColor = true;
//view.Appearance.HorzLine.Options.UseBackColor = true;
//view.OptionsBehavior.AutoPopulateColumns = false;
view.Columns.Clear();
view.IndicatorWidth = 40;
//view.OptionsNavigation.EnterMoveNextColumn = true;
//view.OptionsSelection.MultiSelect = true;
//view.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
//view.OptionsView.EnableAppearanceEvenRow = true;
//view.OptionsView.EnableAppearanceOddRow = true;
//view.OptionsSelection.EnableAppearanceFocusedCell = true;
//view.OptionsSelection.EnableAppearanceFocusedRow = true;
//view.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.CellFocus;
////view.OptionsBehavior.CopyToClipboardWithColumnHeaders = false;
//view.OptionsView.AllowHtmlDrawHeaders = true;
//view.Appearance.FocusedRow.BackColor = Color.FromArgb(128, 191, 255);
////view.Appearance.FocusedCell.BackColor = Color.White;
////view.Appearance.EvenRow.BackColor = Color.FromArgb(253, 254, 239); //Color.FromArgb(226, 234, 253);
//view.Appearance.SelectedRow.BackColor = Color.FromArgb(128, 191, 255);
if (columns == null || columns.Count <= 0)
return;
columns.ForEach(colInfo =>
{
switch (colInfo.Type)
{
case ColumnType.Text:
AddTextColumn(colInfo, view);
break;
case ColumnType.DropDownList:
AddDropDownColumn<Enum>(colInfo, view);
break;
case ColumnType.CheckBox:
AddCheckBoxColumn(colInfo, view);
break;
case ColumnType.Button:
AddButtonColumn(colInfo, view, colInfo.btn_eventHandler);
break;
default:
AddTextColumn(colInfo, view);
break;
}
});
}
private static void AddTextColumn(ColumnInfo colInfo, DevExpress.XtraGrid.Views.Grid.GridView view)
{
GridColumn gc = GetNewColumn(colInfo);
RepositoryItemTextEdit RichTextBox = new RepositoryItemTextEdit();
RichTextBox.ReadOnly = colInfo.IsReadOnly;
gc.ColumnEdit = RichTextBox;
view.Columns.Add(gc);
}
private static void AddDropDownColumn<TSource>(ColumnInfo colInfo, DevExpress.XtraGrid.Views.Grid.GridView view)
{
GridColumn gc = GetNewColumn(colInfo);
RepositoryItemImageComboBox cobo = new RepositoryItemImageComboBox();
cobo.NullText = "";
cobo.ReadOnly = colInfo.IsReadOnly;
cobo.Items.Clear();
if (colInfo.DataSource != null)
{
//List<TSource> lstSource = colInfo.DataSource as List<TSource>;
//BindRepImageComboBoxEdit<TSource>(cobo, lstSource, colInfo.DisplayName, colInfo.ValueName);
//List<DevComboxItemParam> lstSource = colInfo.DataSource as List<DevComboxItemParam>;
//BindRepImageComboBoxEdit<DevComboxItemParam>(cobo, lstSource, colInfo.DisplayName, colInfo.ValueName);
//foreach (var item in lstSource)
//{
// cobo.Items.Add();
//}
//List<object> lstSource = colInfo.DataSource as List<object>;
//BindRepImageComboBoxEdit<TSource>(cobo, lstSource, colInfo.DisplayName, colInfo.ValueName);
List<TSource> lstSource = colInfo.DataSource as List<TSource>;
BindRepImageComboBoxEdit<TSource>(cobo, (Enum)colInfo.DataSource, colInfo.DisplayName, colInfo.ValueName);
}
else
{
//cobo.Items.AddRange(colInfo.DataSource);
}
gc.ColumnEdit = cobo;
view.Columns.Add(gc);
}
private static void AddCheckBoxColumn(
ColumnInfo colInfo,
DevExpress.XtraGrid.Views.Grid.GridView view
)
{
GridColumn gc = GetNewColumn(colInfo);
RepositoryItemCheckEdit check = new RepositoryItemCheckEdit();
check.Name = "colchkItem" + colInfo.ValueName;
if (colInfo.CheckedValueType == typeof(bool))
{
check.ValueChecked = true;
check.ValueUnchecked = false;
}
else
{
check.ValueChecked = 1;
check.ValueUnchecked = 0;
}
check.ReadOnly = colInfo.IsReadOnly;
gc.ColumnEdit = check;
view.Columns.Add(gc);
}
private static void AddButtonColumn(ColumnInfo colInfo, DevExpress.XtraGrid.Views.Grid.GridView view, EventHandler eventHandler)
{
GridColumn gc = GetNewColumn(colInfo);
RepositoryItemButtonEdit btn = new RepositoryItemButtonEdit();
btn.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
btn.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
btn.Buttons[0].Caption = colInfo.HeaderText;
btn.ReadOnly = colInfo.IsReadOnly;
btn.Click += eventHandler;
gc.ColumnEdit = btn;
view.Columns.Add(gc);
}
/// <summary>
/// 根据列信息创建一个新的GridColumn对象
/// </summary>
/// <param name="colInfo"></param>
/// <returns></returns>
private static GridColumn GetNewColumn(ColumnInfo colInfo)
{
GridColumn gc = new GridColumn()
{
FieldName = colInfo.DataPropertyName,
Caption = colInfo.HeaderText.Replace(@"\n", System.Environment.NewLine),
Width = colInfo.ColumnWidth,
Visible = true
};
gc.OptionsFilter.AllowFilter = false;
gc.OptionsColumn.AllowSort = DefaultBoolean.False;
return gc;
}
}
//public class DevComboxItemParam
//{
// public string ItemName { get; set; }
// public object ItemValue { get; set; }
//}