我希望我的自定义PropertyGrid与student1和student2一起作为节点,使用" Name,Section,Percentage,School"作为两个节点的子节点。 我试过这样:
class StudentClass
{
private string name;
private string section;
private string percentage;
private string school;
[CategoryAttribute("Student1")]
public string School
{
get { return school; }
set { school = value; }
}
[CategoryAttribute("Student1")]
public string Percentage
{
get { return percentage; }
set { percentage = value; }
}
[CategoryAttribute("Student1")]
public string Section
{
get { return section; }
set { section = value; }
}
[CategoryAttribute("Student1")]
public string Name
{
get { return name; }
set { name = value; }
}
private string name1;
[CategoryAttribute("Student2")]
public string Name1
{
get { return name1; }
set { name1 = value; }
}
private string section1;
[CategoryAttribute("Student2")]
public string Section1
{
get { return section1; }
set { section1 = value; }
}
private string percentage1;
[CategoryAttribute("Student2")]
public string Percentage1
{
get { return percentage1; }
set { percentage1 = value; }
}
private string school1;
[CategoryAttribute("Student2")]
public string School1
{
get { return school1; }
set { school1 = value; }
}
}
public Form1()
{
InitializeComponent();
StudentClass sc = new StudentClass();
propertyGrid1.SelectedObject = sc1;
}
输出如下所示:
现在在上面的图片中找到了Student2而不是" Name1,Section1,Percentage1,School1"我想和student1一样显示。 但我没有得到所需的输出。所以请帮助我摆脱这个。 我在VS2010中使用C#Winforms
并建议我如何拒绝列调整大小,即我不应该允许用户调整列的大小。
答案 0 :(得分:2)
您可以使用DisplayName
attribute:
private string name1;
[CategoryAttribute("Student2"), DisplayName("Name")]
public string Name1
{
get { return name1; }
set { name1 = value; }
}
但请注意,如果用户将属性网格置于A-Z模式,它们将最终彼此相邻,没有真正的方法来区分它们。您可能会发现有更合适的方式来表示您的数据。