我在 propertygrid 中定义项目。我的代码在这里:
[DisplayName("Title of book"), CategoryAttribute("Books")]
public string BookName{ get; set; }
使用此代码,我可以从 propertygrid 获取该项目的标签和价值(对于此示例:书名及其价值(例如)学习 C#):
private void button1_Click(object sender, EventArgs e)
{
GridItem gi = propertyGrid1.SelectedGridItem;
while (gi.Parent != null)
{
gi = gi.Parent;
}
foreach (GridItem item in gi.GridItems)
{
ParseGridItems(item); //recursive
}
}
private void ParseGridItems(GridItem gi)
{
if (gi.GridItemType == GridItemType.Category)
{
foreach (GridItem item in gi.GridItems)
{
ParseGridItems(item);
}
}
textBox1.Text += "Lable : "+gi.Label + "\r\n";
if(gi.Value != null)
textBox1.Text += "Value : " + gi.Value.ToString() + "\r\n";
}
我怎样才能得到项目名称?对于这个例子:书名