求助 Devexpress 中PopUpContainerEdit中绑定TreeList的弹出控制

happyer_longlong 2012-11-21 12:01:50
问题描述
1 第一次加载窗体后我我用PopUpContainerEdit中的QueryPopUp事件来设置弹出的Treelist控件的宽度和
PopUpContainerEdit 的宽度一样 如下图

但是缩放了窗体之后 两者宽度变成不一样了如图


请问如何可以保持在窗体缩放之后两个控件的宽度还是保持一致,比较困扰,谢谢。

...全文
1207 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamgis 2014-07-07
  • 打赏
  • 举报
回复
devexpress 13.1仍然存在这个问题,蛋疼。 宽度最小只能到200,
LemonAB 2013-01-29
  • 打赏
  • 举报
回复
感谢LZ的分享~有用
happyer_longlong 2013-01-25
  • 打赏
  • 举报
回复
分享个 在popcontainerEdit中自动弹出树的代码片段

1  创建函数
 /// <summary>
        /// 绑定PopUpContainerEdit数据,弹出的是个树,数据源是AccountingSystem类型的 List列表
        /// </summary>
        /// <param name="dataSourceList">要绑定的数据源</param>
        /// <param name="treelist">要弹出的树</param>
        /// <param name="popEdit">传入的PopUpContainerEdit对象</param>
        /// <param name="fileName">绑定数据源中要显示的字段</param>
        /// <param name="imageCollection">树中显示的节点图片</param>
        private void BindData_PopUpContainer(object dataSourceList, 
            TreeList treelist, 
            PopupContainerEdit 
            popEdit, 
            string fileName, 
            DevExpress.Utils.ImageCollection imageCollection) 
        {
            if (dataSourceList == null)
                return;
            else
            {
                treelist.DataSource = null;           //清空数据源
                treelist.DataSource = dataSourceList; //如果没有数据则绑定数据
                this.CreatePopEditerTree(treelist, popEdit, fileName, imageCollection);
                //为PopContainerEditer 注册自动适应宽度弹出事件
                popEdit.QueryPopUp += new CancelEventHandler(this.PopupContainerEdit_AdjustWidth);
            }
        }
2  creatTree
 /// <summary>
       /// 产生popupcontainerEdit的弹出窗口
       /// </summary>
       /// <param name="treeList">弹出的树</param>
        /// <param name="popucontainerEdit">传入的popucontainerEdit对象</param>
       /// <param name="Name">要绑定的数据源中的字段</param>
       /// <param name="imageCollection">绑定的图片集合</param>
        private void CreatePopEditerTree(TreeList treeList, 
            PopupContainerEdit popucontainerEdit, 
            string Name,
            DevExpress.Utils.ImageCollection imageCollection)
        {
            PopupContainerControl popupControl = new PopupContainerControl();
            try
            {
                popupControl.Height = 200;
                TreeListColumn ID = new TreeListColumn();
                TreeListColumn ParentID = new TreeListColumn();
                TreeListColumn tlcName = new TreeListColumn();
                ID.FieldName = Name;
                ID.SortOrder = SortOrder.Ascending;
                ID.Visible = true;
                ID.VisibleIndex = 0;
                ID.OptionsColumn.ReadOnly = true;
                treeList.Columns.AddRange(new TreeListColumn[] { ID, ParentID, tlcName });
                ID.OptionsColumn.AllowEdit = false;
                treeList.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                treeList.Height = 200;
                treeList.HorzScrollVisibility = ScrollVisibility.Always;
                treeList.VertScrollVisibility = ScrollVisibility.Always;
                treeList.SetDefaultRowHeight();
                treeList.OptionsView.ShowColumns = false;
                treeList.OptionsView.ShowIndicator = false;
                treeList.KeyFieldName = "ID";
                treeList.ParentFieldName = "ParentID";
                treeList.StateImageList = (imageCollection == null ? null : imageCollection);
                Panel panelObject = new Panel();
                panelObject.Dock = DockStyle.Fill;
                panelObject.Controls.Add(treeList);
                popupControl.Controls.Add(panelObject);
                panelObject.Width = treeList.Width;
                popucontainerEdit.Properties.PopupControl = popupControl;
                treeList.Appearance.FocusedCell.BackColor = System.Drawing.Color.DodgerBlue;
                treeList.Appearance.FocusedCell.Options.UseBackColor = true;
                popucontainerEdit.Controls.Add(popupControl);
                treeList.Appearance.FocusedCell.BackColor = System.Drawing.Color.DodgerBlue;
                treeList.Appearance.FocusedCell.Options.UseBackColor = true;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {

            }
        }
3 自动调整弹出的宽度时间函数
  /// <summary>
        /// 调整PopupContainerEdit中元素的宽度和pop保持一致
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PopupContainerEdit_AdjustWidth(object sender, CancelEventArgs e)
        {
            PopupContainerEdit popupedit = (PopupContainerEdit)sender;
            popupedit.Properties.PopupControl.Width = popupedit.Width;
        }
4  树的单击事件
/// <summary>
        /// 查询区域中部门类型popContainerEdit中树的双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Treelist_DepartmentType_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                int id = m_Treelist_DepartmentType.FocusedNode.Id;
                var list = (List<DepartmentType>)m_Treelist_DepartmentType.DataSource;
                if (list == null)
                {
                    return;
                }
                if (list.Count > 0)
                {
                    this.m_DepartmentType = list[id];
                    this.PopupContainerEdit_DepartmentType.Text = this.m_DepartmentType.Name;
                    this.PopupContainerEdit_DepartmentType.Focus();
                    this.PopupContainerEdit_DepartmentType.ClosePopup();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
5 调用示例
this.BindData_PopUpContainer(this.GetDepartmentList(this.m_DepartmentTypeList),
                                                   this.m_Treelist_DepartmentType,
                                                   this.PopupContainerEdit_DepartmentType,
                                                   "Remark",
                                                   this.imageCollection_Department_Tree);
                //注册弹出树的单击事件
                this.m_Treelist_DepartmentType.MouseDoubleClick += new MouseEventHandler(Treelist_DepartmentType_MouseDoubleClick);
Mirror然 2012-11-21
  • 打赏
  • 举报
回复
。。 宽度可以自定义的 其实DV的扩展还是不错的
happyer_longlong 2012-11-21
  • 打赏
  • 举报
回复
  private void PopupContainerEdit_QueryPopUp(object sender, CancelEventArgs e)
        {
            PopupContainerEdit popupedit = (PopupContainerEdit)sender;
            popupedit.Properties.PopupControl.Width = popupedit.Width;
        }
自己搞定了原来只差一步,原来是这样写的
//PopupContainerEdit popEdit = (PopupContainerEdit)sender;
            //for (int i = 0; i < popEdit.Controls.Count; i++)
            //{
            //    popEdit.Controls[i].Width = popEdit.Width;
            //}

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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