title: How can I iterate through a BindingSource items in Compact Framework c#
body: <p>I hope there is somewhere a guru that can help me out on this.</p>
  
  <p>I am creating a custom control for a windows ce mobile device.  I created a property so that the user can bind any source to my control. I need to iterate through the source and get the item value for the display member path.</p>
  
  <p>I declare my source and then create the property. In the construct I have an event registered if the source change so that I can start painting my object again.  This is my first time working with binding source from this angle. Am I missing something or using it wrong? Here is some code snippets</p>
  
  <pre><code>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
              }
          }
  </code></pre>
  
  <p>Thanks in advanced.</p>
  
  <p>Regards
  Riaan</p>
  
  <p>EDIT:</p>
  
  <p>Dude I know you use on paint method to paint, this is an example of what I want to do. I create everything from scratch, the entire control is drawn from code and I override all the needed events.  Maybe set the _bindingCollection.DataMember in the DisplayMemberPath? Will that then give the item when iterating through the source? Will test now and post answer if it works. Please no more comments or answers telling me to use on paint or something like that. Concentrate on question of getting the display member value from the collection :)</p>
  
  <p>Edit: Found the answer
  Ok sorry this was actually a really stupid question that I asked while being busy with a lot of things.  This was actually easy to get the property value.</p>
  
  <pre><code>        for (int index = 0; index &lt; _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.
  
          }
  </code></pre>
  
  <p>The question can be deleted if someone needs to delete it.  I will leave it here if there is anyone else to much in a hurry for this solution and do not know how to get it.  These are just code snippets and not in anyway methods that can be used.</p>