没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|其它|编辑:郝浩|2011-12-26 21:49:24.000|阅读 2188 次
概述:在项目中使用XtraGrid控件时遇见这样一个问题,要是能够实现通过鼠标改变指定的行高,这样一来,终端用户使用起来便方便多了。但是,XtraGrid控件不能在内部缓存任何数据,因此目前并不能实现通过鼠标来指定行高的功能。然而,您可以自己实现这个功能。要实现此功能,你需要处理GridView控件的MouseDown, MouseUp以及CalcRowHeight事件。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
在项目中使用XtraGrid控件时遇见这样一个问题,要是能够实现通过鼠标改变指定的行高,这样一来,终端用户使用起来便方便多了。»更多DevExpress开发资源与帮助文档
但是,XtraGrid控件不能在内部缓存任何数据,因此目前并不能实现通过鼠标来指定行高的功能。然而,您可以自己实现这个功能。要实现此功能,你需要处理GridView控件的MouseDown, MouseUp以及CalcRowHeight事件。在MouseDown和MouseUp事件中就会涉及到改变行的大小。而在CalcRowHeight事件处理器中,你得为指定的行设置有效的行高。通过下面的代码示例可以展示一个此功能的实现:
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Grid3 { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private DevExpress.XtraGrid.GridControl gridControl1; private DevExpress.XtraGrid.Views.Grid.GridView gridView1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form 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.gridControl1 = new DevExpress.XtraGrid.GridControl(); this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView(); ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit(); this.SuspendLayout(); // // gridControl1 // this.gridControl1.Dock = System.Windows.Forms.DockStyle.Fill; // // gridControl1.EmbeddedNavigator // this.gridControl1.EmbeddedNavigator.Name = ""; this.gridControl1.Location = new System.Drawing.Point(0, 0); this.gridControl1.LookAndFeel.SkinName = "Money Twins"; this.gridControl1.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin; this.gridControl1.LookAndFeel.UseDefaultLookAndFeel = false; this.gridControl1.LookAndFeel.UseWindowsXPTheme = false; this.gridControl1.MainView = this.gridView1; this.gridControl1.Name = "gridControl1"; this.gridControl1.Size = new System.Drawing.Size(776, 422); this.gridControl1.TabIndex = 0; this.gridControl1.UseEmbeddedNavigator = true; this.gridControl1.ViewCollection.AddRange (new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView1}); // // gridView1 // this.gridView1.GridControl = this.gridControl1; this.gridView1.Name = "gridView1"; this.gridView1.OptionsCustomization.AllowRowSizing = true; this.gridView1.CalcRowHeight += new DevExpress.XtraGrid.Views.Grid.RowHeightEventHandler(this.gridView1_CalcRowHeight); this.gridView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gridView1_MouseDown); this.gridView1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.gridView1_MouseUp); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(776, 422); this.Controls.Add(this.gridControl1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit(); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } Hashtable rowsSizes; const int defaultRowHeight = 30; private void Form1_Load(object sender, System.EventArgs e) { rowsSizes = new Hashtable(); InitData(); FillData(); InitGridColumns(); InitDataEvents(); } //<gridControl1> private DataTable data; private void InitData() { data = new DataTable("ColumnsTable"); data.BeginInit(); AddColumn(data, "ID", System.Type.GetType("System.Int32"), true); AddColumn(data, "First Name", System.Type.GetType("System.String")); AddColumn(data, "Last Name", System.Type.GetType("System.String")); AddColumn(data, "Payment Type", System.Type.GetType("System.String")); AddColumn(data, "Customer", System.Type.GetType("System.Boolean")); AddColumn(data, "Payment Amount", System.Type.GetType("System.Single")); data.EndInit(); } //</gridControl1> private void AddColumn(DataTable data, string name, System.Type type) { AddColumn(data, name, type, false); } private void AddColumn(DataTable data, string name, System.Type type, bool ro) { DataColumn col; col = new DataColumn(name, type); col.Caption = name; col.ReadOnly = ro; data.Columns.Add(col); } private void FillData() { string[,] sNames = new string[,] { { "Elizabeth", "Lincoln"}, {"Yang", "Wang"}, { "Patricio", "Simpson"}, {"Francisco", "Chang"}, { "Ann", "Devon"}, {"Roland", "Mendel"}, { "Paolo", "Accorti"}, {"Diego", "Roel"}}; string[] sType = new string[] {"Visa", "Master", "Cash"}; data.Clear(); Random rnd = new Random(); for(int i = 0; i <= sNames.GetUpperBound(0); i++) data.Rows.Add(new object[] {i + 1, sNames[i,0], sNames[i,1], sType[i % 3], rnd.Next(-1, 1), rnd.Next(10000) * 0.01}); } private void InitGridColumns() { gridControl1.DataSource = data; gridControl1.DefaultView.PopulateColumns(); gridView1.Columns["Payment Amount"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; gridView1.Columns["Payment Amount"].DisplayFormat.FormatString = "c"; gridView1.BestFitColumns(); } private void InitDataEvents() { data.RowDeleting += new DataRowChangeEventHandler(data_RowDeleting); } private void data_RowDeleting(object sender, DataRowChangeEventArgs e) { rowsSizes.Remove(e.Row); } private void gridView1_CalcRowHeight(object sender, DevExpress.XtraGrid.Views.Grid.RowHeightEventArgs e) { object rowHeight = rowsSizes[gridView1.GetDataRow(e.RowHandle)]; if (rowHeight != null) e.RowHeight = Convert.ToInt32(rowHeight); else e.RowHeight = defaultRowHeight; } int resizeStartPos; int resizingRowHandle; private void gridView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = gridView1.CalcHitInfo(e.X, e.Y); if (hi.HitTest == DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitTest.RowEdge) { resizeStartPos = e.Y; resizingRowHandle = hi.RowHandle; } } private void gridView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if (resizingRowHandle >= 0) { resizeStartPos = e.Y - resizeStartPos; object rowSize = rowsSizes[gridView1.GetDataRow(resizingRowHandle)]; int newRowSize; if (rowSize != null) newRowSize = Convert.ToInt32(rowSize); else newRowSize = defaultRowHeight; newRowSize += resizeStartPos; if (newRowSize < defaultRowHeight) newRowSize = defaultRowHeight; rowsSizes[gridView1.GetDataRow(resizingRowHandle)] = newRowSize; resizingRowHandle = -1; } } } }
下载《XtraGrid Suite》
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
文章转载自:慧都控件网面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号