GridControl 使用技巧

导读:本篇文章讲解 GridControl 使用技巧,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

1. 让列宽保持不变,当列特别多的时候出现滚动条  设置 View 中的OptionsView 中的 ColumnAutoWidth = False

2.使某一列出现如下拉框,复选框等效果:设置那一列的ColumnEidt

3.要对单元格的输入进行验证,使用gridview的ValidatingEditor事件

//输入验证
        private void gridView1_ValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e)
        {
            GridView gv = sender as GridView;
            List<string> timeColns = new List<string> { "PEDGRNTM", "PEDREDTM", "MINGRNTM", "GRNEXTENDTM", "MAXGRN1TM", 
                                        "MAXGRN2TM", "FIXGRNTM"};
            if (timeColns.Contains(gv.FocusedColumn.FieldName))
            {
                int inputValue;
                if (!(int.TryParse(e.Value.ToString(), out inputValue) && inputValue >= 0 && inputValue <= 255))
                {
                    e.Valid = false;
                    e.ErrorText = "必须是0到255的整数";
                }
            }
       }

4.要对单元格显示tooltip 需要先添加一个ToolTipController到窗口中,然后实现其GetActiveObjectInfo事件

        //单元格显示tooltip
        private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            if (e.SelectedControl != gridControl1)
                return;
            ToolTipControlInfo info = null;
            //Get the view at the current mouse position
            GridView view = gridControl1.GetViewAt(e.ControlMousePosition) as GridView;
            if (view == null) return;
            //Get the view's element information that resides at the current position
            GridHitInfo hitInfo = view.CalcHitInfo(e.ControlMousePosition);

            if (hitInfo.HitTest == GridHitTest.RowCell)
            {
                //An object that uniquely identifies a row indicator cell
                object o = hitInfo.RowHandle.ToString() + hitInfo.Column.FieldName;
                if (hitInfo.Column.FieldName == "PHASEKIND")
                {
                    string text = "1固定2待定3弹性4关键5跟随6行人7自行车8机动车";
                    info = new ToolTipControlInfo(o, text, "输入含义");
                }
            }
            //Supply tooltip information if applicable, otherwise preserve default tooltip (if any)
            if (info != null)
                e.Info = info;
        } 

4,设置单元格的显示样式

实现gridview 的CustomColumnDisplayText事件

        //修改显示样式
        private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            List<string> boolColns = new List<string> { "NO_DETCT_PHS_TOGETHER", "PED_VEH_TOGETHER", "UNDETERMINED_PHS_APPEAR", "ROAD_SECTION_PED"
                                        , "INUSING"};
            if (boolColns.Contains(e.Column.FieldName))
            {
                switch (e.Value.ToString().Trim())
                {
                    case "1":
                        e.DisplayText = "是";
                        break;
                    case "0":
                        e.DisplayText = "否";
                        break;
                    default:
                        break;
                }
            }
        }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/14825.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!