如何获得一个PropertyGrid中的单元格的值(C#)? [英] How to get a PropertyGrid's cell value (c#)?

查看:1687
本文介绍了如何获得一个PropertyGrid中的单元格的值(C#)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得属性网格项目,项目在C#中的价值?
例如:

How can I get property grid items and item's value in c# ? for example :

Name : Ali
LastName : Ahmadi

(名字和姓氏的是PropertyGrid中的2个属性)

(Name and LastName are 2 properties of propertygrid)

推荐答案

正确答案是:

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";
}

这篇关于如何获得一个PropertyGrid中的单元格的值(C#)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆