2012-08-23 3 views

답변

3

정답은 :

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

PropertyGrid 오브젝트의 컴포넌트 모델 표현 위에 단지 도면 (이름과 성이 PropertyGrid가 2 개 특성이다). 그리드를 보면보다는, 내가 말할 것이다 : 예를 들어, 구성 요소 모델을 보면 :

var props = TypeDescriptor.GetProperties(obj); 
foreach(var prop in props) { 
    string name = prop.DisplayName; 
    if(string.IsNullOrEmpty(name)) name = prop.Name; 
    Console.WriteLine("{0}: {1}", name, prop.GetValue(obj)); 
} 
관련 문제