2010-05-09 3 views

답변

3

가장 간단한 해결책은 DataTable과 변환하고 GridView를 바인딩하는 것입니다.

DataTables는 원하는 모든 데이터 바인딩 지원을 지원하며 행을 추가 및 제거 할 수 있습니다.

일단 사용자가 완료되면 데이터 테이블의 내용을 사전에 다시 복사 할 수 있습니다.

나이와 지저분하지만 일을 끝내야합니다.

Dictionary<string, string> dict = new Dictionary<string, string>(); 
dict.Add("foo", "bar"); 

//translate and bind 
DataTable dt = new DataTable(); 
dt.Columns.Add("Key", typeof(string)); 
dt.Columns.Add("Value", typeof(string)); 
dict 
    .ToList() 
    .ForEach(kvp => dt.Rows.Add(new object [] {kvp.Key,kvp.Value})); 

//allows you to add uniqueness constraint to the key column :-) 
dt.Constraints.Add("keyconstraint", dt.Columns[0], true); 

myDataGridView.DataSource = dt; 

그리고 DICT로 다시 번역 :

Dictionary<string, string> dict = new Dictionary<string, string>(); 
DataTable dt = (DataTable)myDataGridView.DataSource; 
dt.AsEnumerable() 
    .ToList() 
    .ForEach(row => dict.Add(row[0] as string, row[1] as string)); 
0

사전과 같은 데이터 구조를 표시하는 데는 여러 가지 방법이 있으며, 모두 사용 된 기술과 UI에 부여하려는 레이아웃에 따라 다릅니다.
그리드가 가장 단순하다고 생각하지만 다른 컨트롤을 사용해 볼 수도 있습니다.
사용자 환경을 개선하고 사용자 인터페이스를 개선하려면 WPF를 연구하는 것이 좋습니다.이 기술을 사용하면 레이아웃을 데이터 구조에 제공하고 최상의 결과를 얻을 때까지 쉽게 변경할 수 있습니다.

+0

나는 슬프게도, 윈폼으로 제한입니다. 간단한 코드 예제를 보여 주거나 링크 할 수 있습니까? – mafu

+0

다음은 예입니다.하지만 Google을 사용하면 많은 것을 찾을 수 있습니다. http://www.dev102.com/2008/03/07/binding-a-wpf-control-to-a-dictionary/ –

관련 문제