0
PropertyGrid 속성 컬렉션에서 CheckListBox가되도록 UITypeEditor 클래스가 있습니다. 예를 들어 식료품 목록에 제품 (과일, 야채) 카테고리를 만들고이 카테고리에 속하는 제품을 선택해야하는 모든 제품 목록을 만듭니다. 그. 나는 빈 식료품 목록 새로운 카테고리 "Fruits"를 추가하고,이 카테고리는 "사과", "배", "바나나"가 포함 된 제품의 글로벌 목록에서 선택됩니다. 다음으로 "야채"와 같은 다른 카테고리를 만들고 일부 야채의 전체 목록에서 선택하고 싶습니다. 문제는 후자의 범주를 수립 한 이후이며 다른 모든 범주는 동일한 일련의 제품을받습니다. 여기에 코드입니다 :PropertyGrid의 CheckListBox 속성 컬렉션
public class CheckedListBoxUiTypeEditor : UITypeEditor
{
private readonly CheckedListBox _checklisbox1 = new CheckedListBox();
private IWindowsFormsEditorService _es;
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override bool IsDropDownResizable => true;
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
_es = provider.GetService(typeof (IWindowsFormsEditorService)) as IWindowsFormsEditorService;
}
if (_es != null)
{
LoadValues(value);
_es.DropDownControl(_checklisbox1);
}
_result.Clear();
foreach (string str in _checklisbox1.CheckedItems)
{
_result.Add(str);
}
return _result;
}
private readonly List<string> _defaultList = FormLas.ListAll;
private readonly List<string> _result = new List<string>();
private void LoadValues(object value)
{
Hashtable table = new Hashtable();
foreach (string str in _defaultList)
{
table.Add(str, false);
}
_checklisbox1.Items.Clear();
foreach (DictionaryEntry dic in table)
{
_checklisbox1.Items.Add(dic.Key, (bool) dic.Value);
}
if (((List<string>) value).Count > 0)
{
foreach (string str in (List<string>)value)
{
for (int i = 0; i < _checklisbox1.Items.Count; i++)
{
if (str == _checklisbox1.Items[i])
{
_checklisbox1.SetItemChecked(i, true);
}
}
}
}
}
}