2010-11-19 6 views
0

나는 API에서 dictionary <string, string>을 받는다.listview, gridview에 동적 데이터 표시

나는 두 개의 열

로 이름과 값으로 그리드 뷰에서 내 WPF 양식에이 데이터를 표시해야
<ListView Name="LstCustomProperties" ItemsSource="{Binding CustomPropertyTable}"> 
    <ListView.View> 
    <GridView> 
     <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Key}" /> 
     <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Value}" /> 
    </GridView> 
    </ListView.View> 
</ListView> 

또한 새로운 항목을 추가하거나 삭제 버튼을 추가하는 형태에 두 개의 버튼을 가지고 항목을 삭제하십시오. 사용자가 확인을 클릭하면 사전은 목록보기의 현재 이름, 값 쌍에 따라 업데이트됩니다. 나는 listview 또는 shud에서 현재 데이터를 추가하고 수정하는 방법을 얻지 못한다. 나는 다른 컨트롤을 사용한다.

답변

1

여기서 ObservableCollection을 사용하는 것이 좋습니다. 그래서 컬렉션에서 어떤 아이템이라도 insert/update/delete되면 UI가 자동으로 새로 고침됩니다. 당신이 CustomPropertyTable 아무것도를 추가 할 때

public class CustomDictionary 
{ 
    public string Key { get; set; } 
    public string Value { get; set; } 

    public CustomDictionary(string key, string value) 
    { 
     this.Key = key; 
     this.Value = value; 
    } 
} 

public class CustomDictionaryCollection : ObservableCollection<CustomDictionary> 
{ 

} 


public class MyData 
{ 
    public CustomDictionaryCollection CustomPropertyTable { get; set; } 

    public MyData() 
    { 
     this.CustomPropertyTable.Add(new CustomDictionary("myKey", "myValue")); 
    } 
} 

는 이제 ListView가 자동으로 업데이트받을 것이다 :

은 다음 예를 참조하십시오.

희망이 내가 개체에 추가하지 않으

+0

가 직접 그리드와 때에 사용자가 클릭 객체에 저장되며, API는 데이터 저장소를 업데이트에있을 것입니다 도움이됩니다. – Mohit

+0

휴가 중이므로 너무 늦게 받아 들여서 죄송합니다. 사용자가 목록보기에서 값 구성원을 편집 할 수있게하려면 한 가지 더 큰 도움이 될 것입니다. – Mohit

관련 문제