8,834
社区成员
发帖
与我相关
我的任务
分享
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);
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;
//}