简单实现PropertyGrid编辑Dictionary功能

这篇博客介绍了如何简单实现一个PropertyGrid编辑Dictionary功能,特别是当Dictionary的Key和Value都是枚举类型时。内容包括自制包含ListBox、ComboBox、Button和Label的弹出窗体,以及继承UITypeEditor类来重写EditValue和GetEditStyle方法,设置弹出窗口为DictionaryUITypeEditorForm。通过添加特定的Editor特性,可以在Dictionary属性上应用这个自定义编辑器。
摘要由CSDN通过智能技术生成

本Dictionary的Key和Value都是枚举类型,本例并没实现添加和删除功能,只有编辑功能。

(1)自制弹出窗体

四个控件,ListBox:lBox,ComboBox:cBox,Button:btnOk,还有个Label。

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

namespace WindowsFormsApplication2
{
    public partial class FrmDictionaryEditor : Form
    {
        private IDictionary dic;
        private List<string> cBoxList;
        private List<string> lBoxList;
        private bool initFinished = false;
        public FrmDictionaryEditor(IDictionary dic)
        {
            InitializeComponent();
            this.MinimumSize = this.Size;
            this.MaximumSize = this.Size;
            InitData(dic);
        }

        private void InitData(IDictionary dic)
        {
            this.dic = dic;
            this.lBoxList = new List<string>();
            foreach (var item in dic.Keys)
            {
             
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值