Rightthen

Rightthen

  • NA
  • 31
  • 14.8k

BeginInvoke on PropertyInfo of Items property for ComboBox

Jul 8 2013 4:43 AM
Dear Fellows,

The below written code works when i try to take the items Collection
as a whole and then apply index to it. outside of BeginInvoke.

//propName = ComboBoxProperties.Items; 
PropertyInfo comboItems = typeof(ComboBox).GetProperty( propName.ToString().Trim() ) ;
var a = comBox_.BeginInvoke(new Func<object, Object>(comboItems.GetValue), comBox_); 
object c = null;
c = comBox_.EndInvoke(a);
retVal = (((ComboBox.ObjectCollection)c)[(int)propIndex]);

 
but when i try to apply index inside BeginInvoke itself it does not work gives an exception of 

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.

i.e when i do like this


delegate object getItemDlg ( object comBox, object[] index );   



PropertyInfo comboItems = typeof(ComboBox).GetProperty( propName.ToString().Trim() ) ; object[] index = { propIndex };  

var a = comBox_.BeginInvoke( new getItemDlg(comboItems.GetValue), comBox_, index ); object c = null;

c = comBox_.EndInvoke(a);
retVal = c;


i have tried using Func<object,object[],object> and

var a = comBox_.BeginInvoke( new getItemDlg(comboItems.GetValue), new object[]{ comBox_, index });
but to no avail

specifically i would like to know how does one get indexed properties with begin invoke

Thanks
Regards

Answers (2)