나는이 점을 도와 줄 수있는 전문가가 있기를 바랍니다.Compact Framework의 BindingSource 항목을 반복 할 수있는 방법 C#
Windows CE 모바일 장치 용 사용자 지정 컨트롤을 만들고 있습니다. 사용자가 모든 소스를 내 컨트롤에 바인딩 할 수 있도록 속성을 만들었습니다. 소스를 반복하고 표시 멤버 경로에 대한 항목 값을 가져와야합니다.
내 소스를 선언 한 다음 속성을 만듭니다. 컨스트럭션에서 원본을 변경하면 이벤트가 등록되어 오브젝트를 다시 그리기 시작할 수 있습니다. 이 각도에서 소스 바인딩으로 작업 한 것은 이번이 처음입니다. 내가 누락되었거나 잘못 사용하고 있습니까? 다음은 일부 코드입니다
private BindingSource _bindingCollection;
public object DataSource
{
set { _bindingCollection.DataSource = value; }
}
public string DisplayMemberPath { get; set; }
ctor()
{
_bindingCollection.DataSourceChanged += _bindingCollection_DataSourceChanged;
}
void _bindingCollection_DataSourceChanged(object sender, EventArgs e)
{
foreach (var item in _bindingCollection)
{
//I am stuck here on getting the value from the item that is
// specified by DisplayMemberPath to paint my objects on the control
//I can only paint on the control and cannot add any controls to it.
//So here a method is called with the value as a parameter and the
//Graphics object will draw the string
}
}
고맙습니다.
감사 리안
편집 :
야 나는 당신이 페인트 도장 방법에 사용 알고, 이것은 내가 원하는 무엇의 예입니다. 나는 처음부터 모든 것을 만들고 코드에서 전체 컨트롤을 가져오고 필요한 모든 이벤트를 재정의합니다. 어쩌면 DisplayMemberPath에 _bindingCollection.DataMember를 설정 했습니까? 그런 다음 소스를 반복 할 때 항목을 제공합니까? 지금 테스트를하고 작동하면 답변을 게시합니다. 페인트 나 그와 비슷한 것에 대해 더 이상 언급하지 말아주세요. 컬렉션에서 디스플레이 멤버 값을 얻는 것에 대해 집중 해주십시오.
편집 : 답변을 찾았습니다. 죄송합니다. 이것은 실제로 많은 것들로 바쁘다고하면서 나는 정말 바보 같은 질문이었습니다. 이것은 실제로 속성 값을 얻기 쉽습니다.
for (int index = 0; index < _bindingCollection.Count; index++)
{
var propertyValue = _bindingCollection[index].GetType().GetProperty(DisplayMemberPath).GetValue(_bindingCollection[index], null);
// Can do anthing now with the value here or just create a
//method of returning this value with this line of code on top.
}
누군가 삭제해야하는 경우 질문을 삭제할 수 있습니다. 나는이 솔루션을 위해 서둘러 많은 사람들이 있고 그것을 얻는 방법을 모른다면 여기에 남겨 둘 것입니다. 이것들은 단지 코드 조각 일 뿐이며 어쨌든 사용할 수있는 방법이 아닙니다.
DataSourceChanged에 내용을 그려서는 안되며 Paint 이벤트를 사용해야합니다. –