2013-04-18 2 views
0

C# windows Form 프로젝트의 데이터 바인딩 문제가 있습니다. .NET Framework 4 클라이언트 프로필을 사용했습니다. 그리고 IDE는 Visual Studio 2010 C#의 표현판입니다. 다음과 같은 수업이 있습니다.C#의 DataBind - 클래스의 Object 속성에 대한 ComboBox의 selectedvalue

public myClass() 
    { 
     name = string.Empty; 
     dataType = DataTypes.Bool; //property with enum created by me 
     isList = false; 
     filterValue = new object(); 
    } 

다음 profile.csv 파일이 있습니다. 내 양식 중 하나에서, 나는 콤보 박스가 있고 그 데이터 소스는 csv 파일의 데이터를 포함하는 datatable이다.

private void form_load() 
{ 
ComboBox comboBox = new ComboBox(); 
this.Controls.Add(comboBox); 
comboBox.Name = attribute.Name.Replace(" ", string.Empty); 
comboBox.DisplayMember = attribute.Name; 
comboBox.DataSource = attributeValueDataSource.Tables[tableName].DefaultView; 
comboBox.SelectedIndex = 0; 
} 

그런 다음이 콤보 상자의 데이터를 내 클래스에 바인딩합니다. 내 데이터 바인딩 위와 다른 다른 방법으로 및 콤보 상자가 동적으로 만들어 지므로 아래의 메서드에서 이름으로 내 콤보 상자를 발견했습니다.

private void Method_1 
{ 
control = this.Controls.Find(attrName, true); 
ComboBox specificControl = (ComboBox)control[0]; Binding attributeBinding = 
new Binding(SelectedValue, attributeSelectionController.FilterAttributeModels[attributeCount] , FilterValue, true, DataSourceUpdateMode.OnPropertyChanged, string.Empty, F); 
attributeBinding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged; specificControl.DataBindings.Add(attributeBinding); 
} 

그 상태가 괜찮은 것 같습니다. 그러나 이벤트 호출 및 프로그램 흐름을 바인딩 할 때 set 속성 메서드로 이동하면 value.GetType()은 string 또는 integer 또는 다른 데이터 형식 대신 combobox 항목의 selectedValue 유형으로 system.data.datarowview를 반환합니다. 데이터 소스를 설정하는 동안 combox에 대한 값 멤버를 설정하려고했습니다. 그러나 아무 도움도. 어느 누구도 그것에 도울 수 있습니까? 나는 긴급한 해결책이 필요하다.

+0

알아낼 수 없습니다. 명령 때문이에요. – Iris

답변

1

마지막으로 문제를 파악할 수 있습니다. 양식로드 방법에서 아래 줄의 순서를 변경했습니다.

comboBox.DisplayMember = attribute.Name; 
comboBox.DataSource = attributeValueDataSource.Tables[tableName].DefaultView; 

comboBox.DataSource = attributeValueDataSource.Tables[tableName].DefaultView; 
comboBox.DisplayMember = attribute.Name; 
combox.ValueMember = attribute.Name; 

그런 다음 그것을 작동합니다. :)

** 나를 도와주는 친구에게 신용하십시오.

+1

답을 수락하는 것을 잊지 마십시오. 당신은 48 시간 후에 그것을 할 수 있어야합니다. – Neolisk

관련 문제