DevExpress.XtraTreeList.TreeList treeList 用过这个控件的 单击打开节点,双击获取数据

TLJewel 2008-05-09 05:28:46

/// <summary>
/// 注册事件
/// </summary>
void RegEvent()
{
treeList.DoubleClick += new EventHandler(treeList_DoubleClick);
treeList.DoubleClick += new EventHandler(treeList_DoubleClick);
}

void treeList_DoubleClick(object sender, EventArgs e)
{
btnOk.PerformClick();
}

/// <summary>
/// 确定
/// </summary>
private void btnOk_Click(object sender, EventArgs e)
{
object item = this.bsDept.Current;
if (item != null)
{
this.dept = item as Dept;
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
CommonTools.ShowMsg("请选择部门");
}
}

/// <summary>
/// 取消
/// </summary>
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}

/// <summary>
/// 获取部门
/// </summary>
public static bool GetDept(out Dept dept)
{
using(SelectDeptForm form = new SelectDeptForm())
{
//加载数据
form.LoadData();
if (form.ShowDialog() == DialogResult.OK)
{
dept = form.dept.Copy();
return true;
}
}
dept = null;
return false;
}

我想时间的功能是:单击打开节点,双击获取数据。 还有就是单击选中某个数据,然后点击确定按钮也能实现双击的功能、
我写的代码的结果是,双击两次才能获取数据。单击选中后点确定没有反应,

Dept 是要获取数据的实体类。
会的帮帮忙
...全文
656 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
RicahrdTang 2010-07-18
  • 打赏
  • 举报
回复
用委托可以吗,,那个+=不是也把原来的功能加上吗,本来双击就有展开功能啊。。。
TLJewel 2008-05-12
  • 打赏
  • 举报
回复
treeList有没有双击某条数据打开,单击就打开节点的功能?
TLJewel 2008-05-12
  • 打赏
  • 举报
回复
bsDept 是bindingsource ,看来问题不是很清楚
ziseliuxingzh 2008-05-12
  • 打赏
  • 举报
回复
up
patrickpan 2008-05-10
  • 打赏
  • 举报
回复
object item = this.bsDept.Current;
这个bsDept不知道什么意思。
这样应该可以吧:
object item = treeList.FocusedNode;
TLJewel 2008-05-09
  • 打赏
  • 举报
回复
这个问题很简单的,基本上等于散分贴了,我是没事做才和大家研究下的
The XtraTreeList Suite is the first comprehensive TreeList control for Visual Studio.NET. It was built from the ground up in C# and is optimized to take full advantage of the .NET Framework. The XtraTreeList is a multi-purpose data visualization system that can display information as a TREE, a GRID, or a combination of both - in either data-bound or unbound mode. This unique synergy between a traditional grid and a traditional treeview allows you to create cutting-edge and visually appealing application interfaces for your end-users. With industry-leading innovations such as full XP Theme support, Dynamic Data Loading for ultra fast display of information, and unrivaled summary and customization capabilities, the XtraTreelist will allow you to deliver more - in less time - than you ever thought possible. The XtraTreeList fully exploits ADO.NET technologies and can also be used in unbound mode (with ultra-fast dynamic data loading). Its data source can use any class that implements an IList interface, and just like the XtraGrid, the XtraTreeList does NOT cache any data and as result has a small memory footprint and performs data operations as fast as your data can be obtained. In addition, the XtraTreeList fully supports our XtraEditors Library so as to provide you with a huge collection of individual editors - from drop down calendars to combo boxes. Developer Express was the first commercial component vendor in the .NET marketplace to offer the FULL C# SOURCE to all of its components. As such, the XtraTreeList ships with full component source - so you can customize the control as your needs dictate without any limitations or hassles. All Developer Express products are warranted by a 60 day no questions asked money back guarantee. If they do not suit your requirements, you are free to ask for a refund within this period. And of course, all of our components can be distributed royalty free!Total Control, Flexibility and PowerThe Only No Limits TreeList Available for .NETLearn more about the XtraTreeList....
DevExpress打印相关代码 using System; using System.Windows.Forms; using DevExpress.XtraPrinting; using System.Xml.Serialization; namespace MyDevExpressDemo { /// /// PrintSettingController 的摘要说明。 /// public class PrintSettingController { PrintingSystem ps = null; string formName=null; DevExpress.XtraPrinting.PrintableComponentLink link=null; /// /// /// /// 要打印的部件 /// 此部件对应的布局信息 public PrintSettingController(IPrintable control,string FormName) { formName=FormName; ps=new DevExpress.XtraPrinting.PrintingSystem(); link=new DevExpress.XtraPrinting.PrintableComponentLink(ps); ps.Links.Add(link); link.Component=control; ps.PageSettingsChanged-=new EventHandler(ps_PageSettingsChanged); LoadPageSetting(); ps.PageSettingsChanged+=new EventHandler(ps_PageSettingsChanged); ps.AfterMarginsChange+=new MarginsChangeEventHandler(ps_AfterMarginsChange); } public void Preview() { try { if(DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable) { Cursor.Current=Cursors.AppStarting; if(_PrintHeader!=null) { PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter; phf.Header.Content.Clear(); phf.Header.Content.AddRange(new string[] {"",_PrintHeader,""}); phf.Header.Font=new System.Drawing.Font("宋体",14,System.Drawing.FontStyle.Bold); phf.Header.LineAlignment=BrickAlignment.Center; } link.PaperKind=ps.PageSettings.PaperKind; link.Margins=ps.PageSettings.Margins; link.Landscape=ps.PageSettings.Landscape; link.CreateDocument(); ps.PreviewForm.Show(); } else { Cursor.Current=Cursors.Default; MessageBox.Show("打印机不可用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { Cursor.Current=Cursors.Default; } } /// /// 打印控制器 /// /// 要打印的部件 public PrintSettingController(IPrintable control) { if(control==null)return; Control c=(Control)control; formName=c.FindForm().GetType().FullName+"."+c.Name; ps=new DevExpress.XtraPrinting.PrintingSystem(); link=new DevExpress.XtraPrinting.PrintableComponentLink(ps); ps.Links.Add(link); link.Component=control; ps.PageSettingsChanged-=new EventHandler(ps_PageSettingsChanged); LoadPageSetting(); ps.PageSettingsChanged+=new EventHandler(ps_PageSettingsChanged); ps.AfterMarginsChange+=new MarginsChangeEventHandler(ps_AfterMarginsChange); } public void ExportToHtml() { try { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出HTML文件"; fd.RestoreDirectory=true; fd.Filter="HTML文件|*.htm"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { // if(obj is DevExpress.XtraGrid.GridControl) // { // ((DevExpress.XtraGrid.GridControl)obj).ExportToHtml(fd.FileName); // MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } // else if(obj is DevExpress.XtraTreeList.TreeList) // { link.CreateDocument(); ps.ExportToHtml(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } } } } finally { } } /// /// 网格分组时要导出,请使用这个, /// public void GridGroupToExcel() { DevExpress.XtraGrid.GridControl grid=this.link.Component as DevExpress.XtraGrid.GridControl; if(grid!=null) { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出Excel文件"; fd.RestoreDirectory=true; fd.Filter="Excel文件|*.xls"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { grid.ExportToExcel(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } } public void ExportToExcel() { try { using(SaveFileDialog fd=new SaveFileDialog()) { fd.Title="导出Excel文件"; fd.RestoreDirectory=true; fd.Filter="Excel文件|*.xls"; fd.FilterIndex=1; if(fd.ShowDialog()==DialogResult.OK) { // if(obj is DevExpress.XtraGrid.GridControl) // { // ((DevExpress.XtraGrid.GridControl)obj).ExportToExcel(fd.FileName); // MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } // else if(obj is DevExpress.XtraTreeList.TreeList) // { link.CreateDocument(); ps.ExportToXls(fd.FileName); MessageBox.Show("文件导出成功","导出",MessageBoxButtons.OK,MessageBoxIcon.Information); // } } } } finally { } } string _PrintHeader=null; /// /// 打印时的标题 /// public string PrintHeader { set { _PrintHeader=value; } } /// /// 进行打印 /// public void Print() { try { if(DevExpress.XtraPrinting.PrintHelper.IsPrintingAvailable) { if(_PrintHeader!=null) { PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter; phf.Header.Content.Clear(); phf.Header.Content.AddRange(new string[] {"",_PrintHeader,""}); phf.Header.Font=new System.Drawing.Font("宋体",14,System.Drawing.FontStyle.Bold); phf.Header.LineAlignment=BrickAlignment.Center; } link.PaperKind=ps.PageSettings.PaperKind; link.Margins=ps.PageSettings.Margins; link.Landscape=ps.PageSettings.Landscape; link.CreateDocument(); link.CreateDocument(); ps.Print(); } else { Cursor.Current=Cursors.Default; MessageBox.Show("打印机不可用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { } } private void ps_AfterMarginsChange(object sender, MarginsChangeEventArgs e) { SavePageSetting(); } private void ps_PageSettingsChanged(object sender, EventArgs e) { SavePageSetting(); } //获取页面设置信息 void LoadPageSetting() { try { string path=System.Windows.Forms.Application.StartupPath+"\\PrintLayout"; if(!System.IO.Directory.Exists(path)) { return; } path+="\\"+formName+".xml"; if(!System.IO.File.Exists(path)) { return; } XmlSerializer ser=new XmlSerializer(typeof(UserPageSetting)); UserPageSetting setting=(UserPageSetting)ser.Deserialize(new System.IO.FileStream(path,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.ReadWrite)); System.Drawing.Printing.Margins m=new System.Drawing.Printing.Margins(setting.Left,setting.Right,setting.Top,setting.Bottom); ps.PageSettings.Assign(m,(System.Drawing.Printing.PaperKind)setting.PaperKind,setting.Landscape); } catch{} } /// /// 保存当前网格的布局 /// void SavePageSetting() { try { string path=System.Windows.Forms.Application.StartupPath+"\\PrintLayout"; if(!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path+="\\"+formName+".xml"; DevExpress.XtraPrinting.XtraPageSettings setting= ps.PageSettings; UserPageSetting s=new UserPageSetting(); s.Landscape=setting.Landscape; s.Left=setting.Margins.Left; s.Right=setting.Margins.Right; s.Top=setting.Margins.Top; s.Bottom=setting.Margins.Bottom; s.PaperKind=(int)setting.PaperKind; XmlSerializer ser=new XmlSerializer(s.GetType()); ser.Serialize(new System.IO.FileStream(path,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.ReadWrite),s); } catch{} } } /// /// 最终用户对某个打印页的设置 /// [Serializable()] public class UserPageSetting { public UserPageSetting() { } public bool Landscape; public int PaperKind; public int Top; public int Bottom; public int Left; public int Right; } }

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧