59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
|
using DevExpress.XtraEditors;
|
|||
|
using DevExpress.XtraEditors.Controls;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using UI.Framework.Entitys;
|
|||
|
using static UserFission.Control_.Enums;
|
|||
|
|
|||
|
namespace UserFission.Control_
|
|||
|
{
|
|||
|
class CategoryControl : PropertyGridEditStyle
|
|||
|
{
|
|||
|
public CategoryControl()
|
|||
|
{
|
|||
|
var listBox = new CheckedListBoxControl();
|
|||
|
foreach (GenderType item in Enum.GetValues(typeof(GenderType)))
|
|||
|
{
|
|||
|
listBox.Items.Add(new CheckedListBoxItem(null, item.ToString()));
|
|||
|
}
|
|||
|
Control = listBox;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 将选着的数据进行展示
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public override string GetValue()
|
|||
|
{
|
|||
|
var listBox = Control as CheckedListBoxControl;
|
|||
|
string[] strs = new string[listBox.CheckedItems.Count];
|
|||
|
int i = 0;
|
|||
|
foreach (var item in listBox.CheckedItems)
|
|||
|
{
|
|||
|
strs[i] = item.ToString();
|
|||
|
i++;
|
|||
|
}
|
|||
|
return string.Join(",", strs);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 将内容在控件里面勾选
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
public override void SetValue(object value)
|
|||
|
{
|
|||
|
var listBox = Control as CheckedListBoxControl;
|
|||
|
var strs = value == null ? new string[] { } : value.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|||
|
int i = 0;
|
|||
|
foreach (var item in listBox.Items)
|
|||
|
{
|
|||
|
listBox.SetItemChecked(i, !string.IsNullOrEmpty(strs.FirstOrDefault(f => f == item.ToString())));
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|