zoukankan      html  css  js  c++  java
  • Dev中常用到的一些基础事件!

       ============================================================

           SetControlReadOnly(xtraTabControl1);

          //将xtraTabControl1中的控件进行循环遍历,并且控件内容只读

           private void SetControlReadOnly(Control control)
            {
                var pro = control.GetType().GetProperty("ReadOnly");
                if(pro!=null)
                {
                    pro.SetValue(control, true, null);
                }
                foreach(Control c in control.Controls)
                {
                    OperateControls(c);
                }
            }

    ============================================================

            /// <summary>
            /// 自定义显示文本
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
            {

                if(e.Column.FieldName== "State")
                {
                    switch (e.Value.ToString().Trim())
                    {
                        case "0":
                            e.DisplayText = "状态一";
                            break;
                        case "1":
                            e.DisplayText = "状态二";
                            break;
                        case "2":
                            e.DisplayText = "状态三";
                            break;
                        default:
                            e.DisplayText = "未知";
                            break;
                    }
                }

           }

    ============================================================

            /// <summary>
            /// 对某个字段(ValveState)进行不同颜色提示
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
            {
                for(int i=0;i<gridView1.RowCount;i++)
                {
                    if(e.RowHandle==i && e.Column.FieldName== "ValveState")
                    {
                        string state = gridView1.GetRowCellValue(i, "ValveState").ToString();
                        if(state=="1")
                        {
                            e.Appearance.ForeColor = Color.Red;
                        }
                    }
                }
            }

    ============================================================

            /// <summary>
            /// GridView没有查询到数据时显示
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
            {
                if (this.gridView1.RowCount != 0) return;
                GirdControlDrawEmptyForeground.DrawEmpty(sender, e);
            }

        /// <summary>
        /// 列表显示为空提示
        /// </summary>
        public static class GirdControlDrawEmptyForeground
        {
            private const string MESSAGE_INFO = "暂无数据.";

            public static void DrawEmpty(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
            {
                Font font = new Font("宋体", 10, FontStyle.Bold);
                SolidBrush solid = new SolidBrush(Color.Black);
                Rectangle rectangle = new Rectangle(e.Bounds.Left, e.Bounds.Top + 2, e.Bounds.Width, e.Bounds.Height);
                e.Graphics.DrawString(MESSAGE_INFO, font, solid, rectangle);
            }
        }

    ============================================================

         注意:

    1..将该列的UnboundType属性设置为bound(默认值)以外的数据类型

    2.为该列设置一个窗体内全局唯一的FieldName,注意这个FieldName甚至不能出现在窗体上其它XtraGrid中。

            /// <summary>
            /// 非数据绑定列的触发事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
            {
                if (e.IsGetData) //绑定行指示列数据显示文本处理
                {
                    if (e.Column.FieldName == "Cancel") //该显示行
                    {
                        var row = e.Row as View_User;  //行数据源
                        if (row != null && row.State == '2')  //指定列
                        {
                            e.Value = "撤销";
                        }
                        else
                        {
                            e.Value = "";
                        }
                    }
                }
            }

    ============================================================

            /// <summary>
            /// 点击选择选中行的某列数据
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btm_ok_Click(object sender, EventArgs e)
            {
                StringBuilder strTemp = new StringBuilder();
                strTemp.Append("'");

                int[] rows = gridView1.GetSelectedRows();  //获取选中数据行信息
                for(int y=0;y<gridView1.RowCount;y++)
                {
                    string ap = gridView1.GetRowCellValue(y, "Name").ToString();
                    for (int i = 0; i < rows.Count(); i++)
                    {
                        if (gridView1.GetSelectedRows()[i] == y)
                        {
                            strTemp.Append(ap);
                            strTemp.Append("','");
                        }
                    }
                }
                MessageBox.Show("选中用户:" + strTemp);
            }

  • 相关阅读:
    让我们来学学css3 media queries的使用吧
    Emmet(zen coding)文档(一)[译文]
    给自己不同网站的密码加密
    Photoshop图层混合模式原理(公式)
    3dsmax设置贴图路径为相对目录
    ImageMagick
    FireBreak框架: 用C++打造多浏览器支持的插件
    粒子滤波算法
    页端3d技术
    RANSAC算法
  • 原文地址:https://www.cnblogs.com/result-xiaoqiang/p/10598418.html
Copyright © 2011-2022 走看看