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
VulpesPosted Jul 8, 2013, 9:26 AM
You might think that Items would be an indexed property but in fact it's just a normal 'named' property which returns a ComboBox.ObjectCollection.
So if you're just invoking PropertyInfo.GetValue, then the only way to do it is how you're doing it now.
FWIW, it would be possible to use a lambda expression which gets the actual item you want and then pass that to BeginInvoke:
RightthenPosted Jul 8, 2013, 11:00 AM
I am very thankful for ur input.
Thanks
Regards