C#开发学习笔记:使用PropertyGridControl编写自定义属性

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DemoCollection
{
    public partial class FormPropertyGridControl : Form
    {
        public FormPropertyGridControl()
        {
            InitializeComponent();
        }

        private void FormPropertyGridControl_Load(object sender, EventArgs e)
        {
            CustomAttribute customAttribute = new CustomAttribute();
            CustomAttribute1 customAttribute1 = new CustomAttribute1();
            CustomAttribute2 customAttribute2 = new CustomAttribute2();

            //实例化一个CustomAttribute1类型的对象,将它赋值给customAttribute的CA1属性
            //这样CA1属性就会展示CustomAttribute1类型对象的属性成员
            customAttribute.CA1 = customAttribute1;
            customAttribute1.CustomDisplayFormart = customAttribute2;

            propertyGridControl1.SelectedObject = customAttribute;//设置要展示属性的对象
            propertyGridControl1.ExpandAllRows();//展开所有属性(包括子属性)
            propertyGridControl1.RowHeaderWidth = 100;//设置自定义属性左边属性名称的宽度

            //设置属性不按A-Z排序
            propertyGridControl1.OptionsBehavior.PropertySort = DevExpress.XtraVerticalGrid.PropertySort.NoSort;

            //设置属性按A-Z排序
            //propertyGridControl1.OptionsBehavior.PropertySort = DevExpress.XtraVerticalGrid.PropertySort.Alphabetical;

            DevExpress.XtraVerticalGrid.Rows.BaseRow br= propertyGridControl1.GetRowByCaption("自定义属性");

            //通过循环遍历设置属性的中文名称
            foreach (DevExpress.XtraVerticalGrid.Rows.PGridEditorRow per in br.ChildRows)
            {
                if (per.Chil
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值