DevExpress,LayoutControl,TreeList,GridControl等
1.显示边框进行折叠
选择一个layoutControlGroupX 将其GroupBordersVisible设置成True,将TextVisiable=True
2. TreeList
2.1需要绑定的数据有ParentFieldName,KeyFieldName,
2.2.1.TeeList前面的连线
启动程序中添加DevExpress.BonusSkins.v13.1.dll
Main中进行注册
[STAThread]
static void Main(params String[] args)
{
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length>= && args[]=="test")
{
Application.Run(new Form1());
}else
{
Application.Run(new F.Studio.DevExpressUI.frmLogin());
}
}
需要设置LookAndFeel(比方Blue),
将UseDefaultLookAndFeel设置成False
//显示checkBox,并执行递归选择
treeList1.OptionsBehavior.AllowRecursiveNodeChecking = true;
treeList1.OptionsView.ShowCheckBoxes = true;
//参考:http://blog.sina.com.cn/s/blog_53b58e7c0101aclk.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using F.Studio.Prime.IService;
using F.Studio.Prime.EFModel;
using DevExpress.XtraTreeList.Nodes; namespace F.Studio.DevExpressUI
{
public partial class frmFuncsConfigEdit : frmEditBase
{
public Sys_FuncsConfig ModifyConfig { get; set; } public frmFuncsConfigEdit()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; #region 配置TreeList imageList1.Images.Add( Properties.Resources.folder);
imageList1.Images.Add( Properties.Resources.folder_open);
imageList1.Images.Add( Properties.Resources.func);
imageList1.Images.Add( Properties.Resources.tag_16x16);
imageList1.Images.Add( Properties.Resources.question_16x16); treeList1.StateImageList = imageList1;
treeList1.SelectImageList = imageList1;
treeList1.ColumnsImageList = imageList1; //显示checkBox,并执行递归选择 treeList1.OptionsView.ShowCheckBoxes = true;
treeList1.OptionsBehavior.AllowIndeterminateCheckState = false;
treeList1.OptionsBehavior.AllowRecursiveNodeChecking = false;
treeList1.OptionsBehavior.Editable = false; treeList1.AfterCheckNode += (s, e) =>
{
Console.WriteLine(e.Node.SelectImageIndex);
};
treeList1.NodesReloaded += (s, e) =>
{
//到这里完成全部Node的挂接!
Console.WriteLine("NodesReloaded"); SetTreeListCheckState();
treeList1.OptionsBehavior.AllowRecursiveNodeChecking = true;
};
treeList1.CreateCustomNode += (s, e) => {
var tag = e.Tag;
Console.WriteLine("CreateCustomNode"); };
treeList1.NodeChanged += (s, e) => {
Console.WriteLine("NodeChanged"); };
treeList1.FocusedNodeChanged += (s, e) => { var list= treeList1.GetDataRecordByNode(e.Node); childBindingSource.DataSource = list;
};
#endregion }
public frmFuncsConfigEdit(Sys_FuncsConfig config):this()
{
sys_FuncsConfigBindingSource.DataSource = config;
IsModify = true;
ModifyConfig = config; }
private void SetTreeListCheckState()
{
Queue<TreeListNode> queue = new Queue<TreeListNode>();
foreach (TreeListNode node in treeList1.Nodes)
{
queue.Enqueue(node);
}; while (queue.Count > )
{
var node= queue.Dequeue(); var isChecked=(bool)node.GetValue("IsChecked");
node.Checked = isChecked;
//treeList1.SetNodeCheckState(node, isChecked ? CheckState.Checked : CheckState.Unchecked, false);
foreach (TreeListNode child in node.Nodes)
{
queue.Enqueue(child);
}
} }
private void frmFuncsConfigEdit_Load(object sender, EventArgs e)
{ Func<List<SysResourceInfo>> fun = () =>
{
return SysResourceInfo.Build();
};
var list = InvokeService<List<SysResourceInfo>>(fun); if (!IsModify)
{
sys_FuncsConfigBindingSource.AddNew();
}
else//修改状态
{ string wehre=string.Format("it.ConfigId={0}",ModifyConfig.ConfigId);
var configItems= Fetch<IFuncsConfigItemsService>().GetList(wehre, "it.RecId");
list.ForEach(item => {
if (item.ResourceType == "目录") return;
if (configItems.Any(ent => ent.ResourceId == item.FuncId))
{
item.IsChecked = true;
}
}); }
sysResourceInfoBindingSource.DataSource = list;
Console.WriteLine(treeList1.AllNodesCount); } private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{ foreach (TreeListNode node in treeList1.Nodes)
{
Console.WriteLine(node.ToString());
}
} private void btnCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using F.Studio.Prime.IService;
using F.Studio.Prime.EFModel;
using DevExpress.XtraTreeList.Nodes;
using F.Studio.Infrastructure; namespace F.Studio.DevExpressUI
{
public partial class frmFuncsConfigEdit : frmEditBase
{
public Sys_FuncsConfig ModifyConfig { get; set; } public frmFuncsConfigEdit()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; #region 配置TreeList imageList1.Images.Add( Properties.Resources.folder);
imageList1.Images.Add( Properties.Resources.folder_open);
imageList1.Images.Add( Properties.Resources.func);
imageList1.Images.Add( Properties.Resources.tag_16x16);
imageList1.Images.Add( Properties.Resources.question_16x16); treeList1.StateImageList = imageList1;
treeList1.SelectImageList = imageList1;
treeList1.ColumnsImageList = imageList1; //显示checkBox,并执行递归选择 treeList1.OptionsView.ShowCheckBoxes = true;
treeList1.OptionsBehavior.AllowIndeterminateCheckState = false;
treeList1.OptionsBehavior.AllowRecursiveNodeChecking = true;
treeList1.OptionsBehavior.Editable = false; treeList1.AfterCheckNode += (s, e) =>
{
treeList1.FocusedNode = e.Node;
Console.WriteLine("AfterCheckNode!");
var r = treeList1.GetDataRecordByNode(e.Node) as SysResourceInfo; r.IsChecked = e.Node.Checked;
treeList1.CloseEditor(); #region (废弃) 如果窗体取消选择,那么取消窗体下的按钮
//if (!e.Node.Checked)
//{
// if (r.ResourceType == "窗体")
// {
// r.Buttons.ForEach(ent => ent.IsChecked = false);
// buttonsBindingSource.ResetBindings(true);
// }
//}
#endregion };
treeList1.NodesReloaded += (s, e) =>
{
//到这里完成全部Node的挂接!
Console.WriteLine("NodesReloaded"); SetTreeListCheckState(); };
treeList1.CreateCustomNode += (s, e) => {
//var tag = e.Tag;
//Console.WriteLine("CreateCustomNode"); };
treeList1.NodeChanged += (s, e) => {
//Console.WriteLine("NodeChanged"); };
treeList1.FocusedNodeChanged += (s, e) => { var list= treeList1.GetDataRecordByNode(e.Node); buttonsBindingSource.DataSource = list;
}; buttonsBindingSource.CurrentItemChanged += (s, e) => {
//var btn= buttonsBindingSource.Current as SysButtonInfo;
//if (btn == null) return;
//Console.WriteLine("CurrentItemChanged:" + btn.IsChecked);
};
#endregion repositoryItemCheckEdit1.CheckedChanged += (s, e) => {
Console.WriteLine("CheckedChanged:");
var btn= gridView1.GetFocusedRow() as SysButtonInfo;
var parent= btn.Parent as SysResourceInfo; if((s as CheckEdit).Checked)
{
parent.Node.Checked = true; } gridView1.CloseEditor();
gridView1.UpdateCurrentRow();
};
}
public frmFuncsConfigEdit(Sys_FuncsConfig config):this()
{
sys_FuncsConfigBindingSource.DataSource = config;
IsModify = true;
ModifyConfig = config; }
private void SetTreeListCheckState()
{
Queue<TreeListNode> queue = new Queue<TreeListNode>();
foreach (TreeListNode node in treeList1.Nodes)
{
queue.Enqueue(node);
}; while (queue.Count > )
{
var node= queue.Dequeue();
var obj= treeList1.GetDataRecordByNode(node) as SysResourceInfo;
var isChecked=(bool)node.GetValue("IsChecked");
obj.Node = node;//建立引用
node.Checked = isChecked;
if (isChecked)
{
var cur = node;
while (cur.ParentNode != null)
{
var rnode = treeList1.GetDataRecordByNode(cur) as SysResourceInfo;
Console.WriteLine(rnode.Title);
cur.ParentNode.Checked = true;
cur = cur.ParentNode;
}
}
treeList1.SetNodeCheckState(node, isChecked ? CheckState.Checked : CheckState.Unchecked, false);
foreach (TreeListNode child in node.Nodes)
{
queue.Enqueue(child);
}
} }
/// <summary>
/// 同步接点状态到绑定数据源
/// </summary>
private void SyncCheckState()
{
Queue<TreeListNode> queue = new Queue<TreeListNode>();
foreach (TreeListNode node in treeList1.Nodes)
{
queue.Enqueue(node);
}; while (queue.Count > )
{
var node = queue.Dequeue();
var obj = treeList1.GetDataRecordByNode(node) as SysResourceInfo;
obj.IsChecked = node.Checked;
foreach (TreeListNode child in node.Nodes)
{
queue.Enqueue(child);
}
}
} private void frmFuncsConfigEdit_Load(object sender, EventArgs e)
{ Func<List<SysResourceInfo>> fun = () =>
{
return SysResourceInfo.Build();
};
var list = InvokeService<List<SysResourceInfo>>(fun); if (!IsModify)
{
sys_FuncsConfigBindingSource.AddNew();
}
else//修改状态
{ string wehre=string.Format("it.ConfigId={0}",ModifyConfig.ConfigId);
var configItems= Fetch<IFuncsConfigItemsService>().GetList(wehre, "it.RecId");
list.ForEach(item => {
if (item.ResourceType == "目录") return;
if (configItems.Any(ent => ent.ResourceId == item.FuncId))
{
item.IsChecked = true; }
//设置按钮
item.Buttons.ForEach(btn =>
{
if (configItems.Any(ent1 => ent1.ResourceId == btn.FuncId))
{
btn.IsChecked = true;
}
});
}); }
sysResourceInfoBindingSource.DataSource = list; treeList1.ExpandAll();
//SetTreeListCheckState(); } private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
sys_FuncsConfigBindingSource.EndEdit();
sysResourceInfoBindingSource.EndEdit();
buttonsBindingSource.EndEdit();
gridView1.CloseEditor(); var ent = sys_FuncsConfigBindingSource.Current as Sys_FuncsConfig;
if (string.IsNullOrWhiteSpace(ent.ConfigName)) throw new Exception("请提供配置名!"); var srv = ServiceLocator.Fetch<IFuncsConfigService>();
if (IsModify)
{
srv.Update(ent);
}
else
{
var newEnt = srv.Add(ent);
ent.ConfigId = newEnt.ConfigId; base.NewRecord = newEnt;
} #region 更新配置 SyncCheckState();
var res = (sysResourceInfoBindingSource.DataSource as List<SysResourceInfo>).Where(entTmp=>entTmp.ResourceType!="目录").ToList(); #region(作废) 被"目录"类型节点递归选中的节点做额外处理
//var nodes = treeList1.GetAllCheckedNodes();
//nodes.ForEach(node =>
//{
// var resIt = treeList1.GetDataRecordByNode(node) as SysResourceInfo;
// if (resIt.ResourceType != "目录")
// {
// resIt.IsChecked = true; // }
//});
#endregion Action act = () => { var newResList = new List<Sys_FuncsConfigItems>(); foreach (var r in res)
{ var newRes = new Sys_FuncsConfigItems();
newRes.ResourceId = r.FuncId;
newRes.ResourceType = r.ResourceType;
newRes.ConfigId = ent.ConfigId;
if (r.IsChecked.Value)
{
newResList.Add(newRes);
} foreach (var btn in r.Buttons)
{
if (btn.IsChecked.Value)
{
var newBtnRes = new Sys_FuncsConfigItems();
newBtnRes.ResourceId = btn.FuncId;
newBtnRes.ResourceType = btn.ResourceType;
newBtnRes.ConfigId = ent.ConfigId;
newResList.Add(newBtnRes);
}
}
}
ServiceLocator.Fetch<IFuncsConfigItemsService>().SetConfigItems(newResList, ent);
};
InvokeService(act); #endregion
DialogResult = System.Windows.Forms.DialogResult.OK;
}
catch (Exception ex)
{
ErrMsg(ex.Message); } } private void btnCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
展开关闭图标
imgList = new ImageList(this.components);
imgList.Images.Add(Properties.Resources.folder);
imgList.Images.Add(Properties.Resources.folder_open);
treeList1.SelectImageList = imgList;
treeList1.StateImageList = imgList; treeList1.AfterCollapse += (s, e) => {
e.Node.ImageIndex = ;
e.Node.SelectImageIndex = ;
};
treeList1.AfterExpand += (s, e) => {
e.Node.ImageIndex = ;
e.Node.SelectImageIndex = ;
};
3.GridControl
3.1.1添建按钮列->参考:http://www.cnblogs.com/zeroone/p/3534783.html
3.1.2 下拉框编辑->http://www.cnblogs.com/zeroone/p/3606224.html
3.2 设置参考列:http://blog.csdn.net/nanchuan/article/details/7664070
gridView1.CustomColumnDisplayText += (s, e) =>
{
if (e.Column.FieldName == "FuncConfigId")
{
var list = FuncsConfigLookUp.Value;
if (list != null)
{
var it = list.FirstOrDefault(ent => ent.ConfigId == int.Parse(e.Value.ToString()));
if (it != null) e.DisplayText = it.ConfigName;
}
}
};
3.3 设置计算列,分组会总等
参考:http://blog.csdn.net/lenovouser/article/details/7405577
gridColumn1.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
gridColumn1.UnboundExpression = "[Amount] * ToDouble(SubString([CostPerUnit],0, CharIndex('(',[CostPerUnit])))";
gridView1.GroupSummary.Add(SummaryItemType.Sum, "gridColumn1", gridView1.Columns["gridColumn1"],"组计:{0}");
注:gridColumn1是一个未帮定列,另外需要开启gridView.OptionsView.ShowFooter=True

3.4判断gridControl 的那个列的单元格被双击
gridControl1.MouseDoubleClick += (s, e) =>
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
GridHitInfo hInfo = gridView1.CalcHitInfo(new Point(e.X, e.Y));
if (!hInfo.InRow) return; //确保点的是数据行而不是标头 var ent = qSymptomRepositoryItemBindingSource.Current as Q_SymptomRepositoryItem;
if (ent == null) return; //hInfo.Column==null 标示点了行头
if (hInfo.Column!=null && hInfo.Column.Caption == "图片")
{
var img=gridView1.GetFocusedValue() as Image;
new frmPhotoDetail(img).ShowDialog();
return;
} //双击其他标示修改
btnModify.PerformClick(); }
};
3.5 启用滚动条 gridView1.OptionsView.ColumnAutoWidth = false;
4.窗体继承
4.1.如果显示设计时错误,需要把两个partial 类的父类都设置下
4.2.如果father是泛型类那么会一直显示设计时错误
4.3.父亲窗体中用From_Load 或重写了OnLoad时,里面不要写代码,如果要写需要加入if(!DesignMode){...}
4.4.在继承窗体上增加按钮,无法显示
5.样式与中文包
将zn-CN 复制到运行目录 执行下列代码
/// </summary>
[STAThread]
static void Main(params String[] args)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); if (args.Length >= && args[] == "test")
{
Application.Run(new Form1());
}
else
{
Application.Run(new F.Studio.DevExpressUI.frmLogin());
}
}
6.DateEdit显示时间
DateEdit如果开启Vista模式并显示日期+时间模式 问题,以前没有涉及过,借机看一下,记录如下:
设置为Vista显示模式(如下图)
参考 :http://www.cnblogs.com/xiaofengfeng/archive/2011/09/07/2169691.html
设置以下属性
dateEdit1.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
dateEdit1.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
设置显示长日期模式(日期+时间):
dateEdit1.Properties.DisplayFormat.FormatString="g"
dateEdit1.Properties.DisplayFormat.FormatType=DateTime
dateEdit1.Properties.EditFormat.FormatString="g"
dateEdit1.Properties.EditFormat.FormatType=DateTime
------------------------------------------------------------------
dateEdit1.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
dateEdit1.Properties.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
dateEdit1.Properties.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
dateEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
dateEdit1.Properties.EditFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
dateEdit1.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
dateEdit1.Properties.EditMask = "yyyy-MM-dd HH:mm:ss";
设置为Vista模式时,如果要显示日期+时间的长日期模式,还需要设置:
VistaTimeProperties.DisplayFormat
VistaTimeProperties.EditFormat
7.treeListLookUpEdit禁止文本框输入
catalogIdSpinEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
DevExpress,LayoutControl,TreeList,GridControl等的更多相关文章
- 关于 DevExpress.XtraTreeList.TreeList 树形控件 的操作
作为一个C#程序员,在写程序时一直以来都使用的微软那一套控件,用起来特别爽,可是最近公司的一个项目用到了DevExpress框架,不用不知道,一用吓一跳,不得不承认这个框架确实很强大,效果也很炫,但是 ...
- DevExpress控件GridControl中的布局详解 【转】
DevExpress控件GridControl中的布局详解 [转] 2012-10-24 13:27:28| 分类: devexpress | 标签:devexpress |举报|字号 订阅 ...
- DevExpress控件-GridControl根据条件改变单元格(Dev GridControl 单元格着色)
DevExpress控件-GridControl根据条件改变单元格颜色,如下图: 解决办法:可以参考:http://www.cnblogs.com/zeroone/p/4311191.html 第一步 ...
- 在Winform开发框架中使用DevExpress的TreeList和TreeListLookupEdit控件
DevExpress提供的树形列表控件TreeList和树形下拉列表控件TreeListLookupEdit都是非常强大的一个控件,它和我们传统Winform的TreeView控件使用上有所不同,我一 ...
- Winforn中DevExpress的TreeList中显示某路径下的所有目录和文件(附源码下载)
场景 Winform中DevExpress的TreeList的入门使用教程(附源码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
- DevExpress的TreeList实现显示本地文件目录并自定义右键实现删除与重命名文件
场景 使用DevExpress的TreeList显示本磁盘下文件目录并在树节点上右键实现删除与添加文件. 效果 自定义右键效果 实现 首先在包含Treelist的窗体的load方法中对treelist ...
- DevExpress中TreeList树样式调整
DevExpress的TreeList默认是没有树状线的,修改TreeLineStyle属性无效,这对于Tree并不好看. 解决方案一 官方解释说对于DevExpress的标准主题是不支持TreeLi ...
- Winform中双击DevExpress的TreeList的树形节点怎样获取当前节点
场景 DevExpress的TreeList怎样设置数据源,从实例入手: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10254 ...
- DevExpress的TreeList实现自定义右键菜单打开文件选择对话框
场景 DevExpress的TreeList实现节点上添加自定义右键菜单并实现删除节点功能: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/det ...
随机推荐
- fusionjs uber开源的通用web插件化开发框架
fusionjs uber开源的web 插件化开发框架 核心特性: 基于插件的开发,依赖注入开发 开箱即用的服务器端渲染,构建结果拆分,模块热加载 Tree-shaking 支持 集成的插件 redu ...
- 不以main为入口的函数
先看一段程序 #include <stdio.h> void test() { printf("Hello Word!\n"); return 0; } 没有main函 ...
- Javascript 的数据是什么数据类型?
Javascript 中的数据都是以 64 位浮点 float 存储的. 所有语言对浮点的精度是很难确定的. 如下代码可以实验到问题. <script> var a = 0.4; var ...
- CCFlow SDK模式开发(有比较详细的代码,以服务的形式与ccflow数据库进行数据交互)
http://www.cnblogs.com/s0611163/p/3963142.html 需求: 1.业务数据要保存在我们自己的数据库里 2.CCFlow有保存草稿的功能,但是领导要求每个 ...
- Tomcat 7 可以修改 Session 默认的 Cookie 名 JSESSIONID 了
Tomcat 7 可以修改 Session 默认的 Cookie 名 JSESSIONID 了 程序员必上的开发者服务平台 —— DevStore 看看下面这个配置: <Contex ...
- java 线程池 ExeutorService
Java线程池 ExecutorService 原文:https://blog.csdn.net/suifeng3051/article/details/49443835/ 本篇主要涉及到的是java ...
- ThinkJava-输入和输出
1/0流的典型使用方式 1.缓冲输入文件 package com.java.io; import java.io.BufferedReader; import java.io.File; impo ...
- Java 字符串 String
什么是Java中的字符串 在 Java 中,字符串被作为 String 类型的对象处理. String 类位于 java.lang 包中.默认情况下,该包被自动导入所有的程序. 创建 String 对 ...
- Java-Runoob-高级教程-实例-字符串:06. Java 实例 - 字符串查找
ylbtech-Java-Runoob-高级教程-实例-字符串:06. Java 实例 - 字符串查找 1.返回顶部 1. Java 实例 - 字符串搜索 Java 实例 以下实例使用了 Strin ...
- 实时计算CEP
实时计算怎么实现: 流计算.....