2010-01-15 3 views
1

BindingSource..works를 통해 엔티티 (W/INotifyPropertyChanged)에 바인딩 된 컨트롤이있는 Windows 양식 (net 2.0)이 있습니다. 내가 값을 변경할 때 그래서Winform BindingSources - 질문

m_PlanItemLookupBindingSource.DataSource = GetBusinessLogic().RetrievePaymentPlanLookups(); // Collection of PaymentPlans 
paymentPlanType.Properties.DataSource = m_PlanItemLookupBindingSource; 
paymentPlanType.Properties.DisplayMember = "Name"; 
paymentPlanType.Properties.ValueMember = "ID"; 
paymentPlanType.DataBindings.Add(new Binding("EditValue", m_PlanBindingSource, "PaymentPlanID", true, DataSourceUpdateMode.OnPropertyChanged, null, "D")); 

agencyComission.DataBindings.Add(new Binding("EditValue", m_PlanBindingSource, "AgencyCommission", true, DataSourceUpdateMode.OnPropertyChanged, null, "P1")); 
billingType.DataBindings.Add(new Binding("Text", m_PlanBindingSource, "BillingType")); 

: 나는 또한 여기 BindingSource..works

를 통해 연결되어 드롭 다운 목록이 같은 형태에

는 관련 코드의 샘플입니다 드롭 다운 목록에서 m_PlanItemLookupBindingSource Current 속성이 변경되는 엔티티의 PaymentPlanID 속성과 함께 변경 될 것이라고 생각했습니다.

조금 혼란 스럽습니다. 미리

감사 스티븐 BindingSource에 상기 제어 값을 취하고 BindingSource에의 위치 등록에 의해 결정된 현재의 목적은 기본 소스에 설정

답변

1

.

따라서 드롭 다운 목록에서 값을 선택하면 기본 개체의 PaymentPlanID 속성이 선택된 새 값으로 설정됩니다. 기본 개체는 BindingSource의 Current 속성에 의해 식별됩니다.

드롭 다운 목록에서 선택한 개체로 현재 속성을 이동하려면 BindingSource에 MoveFirst, MoveLast, MovePrevious 또는 MoveNext 메서드 또는 Position 속성을 사용해야합니다.

다음과 같이 할 수 있습니다. 드롭 다운 목록에서 Changed 또는 ValueChanged 이벤트의 이벤트 처리기에서 BindingSource에 전달할 수있는 인덱스 인 선택한 항목의 인덱스를 가져 오는 중입니다. Position 속성.

Changed or ValueChanged event handler 
    ... 
    int index = DropDownList.ListIndex 
    BindingSource.Position = index 
    ... 
End event handler 

드롭 다운 목록의 드롭 다운 목록에서 EditValue를 PaymentPlanID로 연결하는 데이터 바인딩을 제거해야합니다. 이렇게하면 BindingSource의 Position이 변경되기 전에 기본 개체의 PaymentPlanId가 선택된 값으로 설정되지 않습니다.