Winforms 如何将进度条添加到Telerik RadPropertyGrid?
我使用Telerik WinForms软件包。 My RadPropertyGrid显示一些设置:Winforms 如何将进度条添加到Telerik RadPropertyGrid?,winforms,telerik,propertygrid,Winforms,Telerik,Propertygrid,我使用Telerik WinForms软件包。 My RadPropertyGrid显示一些设置: radPropertyGrid1.SelectedObject = m_db; radPropertyGrid1.ReadOnly = true; 如何将新项目添加为进度条以显示百分比和颜色?它是静态字段,不需要动态更改任何内容 或者作为第二种方法:如何添加带%?的彩色字段为了在RadPropertyGrid中显示进度条,可能的解决方案是使用自定义项。RadPropertyGrid允许您创建
radPropertyGrid1.SelectedObject = m_db;
radPropertyGrid1.ReadOnly = true;
如何将新项目添加为进度条以显示百分比和颜色?它是静态字段,不需要动态更改任何内容
或者作为第二种方法:如何添加带%?的彩色字段为了在RadPropertyGrid中显示进度条,可能的解决方案是使用自定义项。RadPropertyGrid允许您创建和使用自己的自定义值项,允许您添加所需的编辑器以满足您的业务需要。有关此主题的更多信息,请参见: 为了供您参考,我准备了一个示例演示如何实现您的要求。请注意,这是一个示例演示,可能不包括所有可能的情况。根据您的具体需要,可以随意修改或扩展它 请参阅以下代码段:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
public RadForm1()
{
InitializeComponent();
PropertyStoreItem stringItem = new PropertyStoreItem(typeof(string), "String", "Telerik", "Property storing a string value", "Telerik");
RadPropertyStore store = new RadPropertyStore();
store.Add(stringItem);
PropertyStoreItem progressItem = new PropertyStoreItem(typeof(int), "Progress", 40, "Represents a progress bar element.");
store.Add(progressItem);
this.radPropertyGrid1.SelectedObject = store;
this.radPropertyGrid1.CreateItemElement += this.RadPropertyGrid1_CreateItemElement;
}
private void RadPropertyGrid1_CreateItemElement(object sender, CreatePropertyGridItemElementEventArgs e)
{
if (e.ItemElementType == typeof(PropertyGridItemElement))
{
if (e.Item.Name == "Progress")
{
e.ItemElementType = typeof(CustomItemElement);
}
else
{
e.ItemElementType = typeof(DefaultPropertyGridItemElement);
}
}
}
}
public class CustomPropertyGridValueElement : PropertyGridValueElement
{
RadProgressBarElement progressBarElement;
protected override void CreateChildElements()
{
base.CreateChildElements();
progressBarElement = new RadProgressBarElement();
this.Children.Add(progressBarElement);
}
public override void Synchronize()
{
PropertyGridItem item = this.VisualItem.Data as PropertyGridItem;
if (item != null && item.Value != DBNull.Value)
{
this.progressBarElement.Value1 = Convert.ToInt16(item.Value);
}
}
}
public class CustomItemElement : PropertyGridItemElement
{
protected override PropertyGridValueElement CreatePropertyGridValueElement()
{
return new CustomPropertyGridValueElement();
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(PropertyGridItemElement);
}
}
public override bool IsCompatible(PropertyGridItemBase data, object context)
{
return data.Label == "Progress";
}
}
public class DefaultPropertyGridItemElement : PropertyGridItemElement
{
protected override Type ThemeEffectiveType
{
get
{
return typeof(PropertyGridItemElement);
}
}
public override bool IsCompatible(PropertyGridItemBase data, object context)
{
return data.Label != "Progress";
}
}
Thanx Nadya,这正是我想要实现的。