Hi
Hoping someone can help me, I want to make my list sortable, but I won't know what the type is until runtime.
This doesn't work
Type
t = _obj.GetType(); Csla.SortedBindingList<t> sortedList = new Csla.SortedBindingList<t>(t.GetList(parms));Any ideas?
Thanks
I would appreciate some help, I'm a but stuck here with the generics.
I'm trying to make a generic search form that I can pass in a ReadOnlyListBase, and have it just work,
======================================================
This is where I started and it worked fine, until I needed to add sorting. Which is where I got lost.
private void LoadData(object[] parms)
{
try
{
if (this.resultsDataGridView.DataSource != null)
this.resultsDataGridView.DataSource = null;
this.resultsDataGridView.DataSource = Microsoft.VisualBasic.Interaction.CallByName(_obj, "GetList", Microsoft.VisualBasic.CallType.Method, parms);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
System.Threading.Thread.CurrentThread.Abort();
}
}
======================================================
Then I thought generics might work better because the SortedBindingList wanted the child object.
What I'm trying to do is pass in the type of object and type of child object, where I have a ReadOnlyListBase:
public class ClientList : Csla.ReadOnlyListBase<ClientList, ClientInfo>
Then I want to call The GetList method and assign a SortedBindingList of the output to a dataGridView datasource.
LoadData1<QL.View.ClientList, QL.View.ClientInfo>(QL.View.ClientList, QL.View.ClientInfo, parameterValues);
public static void LoadData1<T, C>(T t, C c, object[] parms)
{
object o = Microsoft.VisualBasic.Interaction.CallByName(t.GetType(), "GetList", Microsoft.VisualBasic.CallType.Method, parms);
Csla.SortedBindingList<t> sortedList = new Csla.SortedBindingList<t>(o);
this.resultsDataGridView.DataSource = sortedList;
}
Error 1 'QuickFind.Library.View.ClientList' is a 'type', which is not valid in the given context
Error 2 'QuickFind.Library.View.ClientInfo' is a 'type', which is not valid in the given context
Error 3 The type or namespace name 't' could not be found (are you missing a using directive or an assembly reference?)
Error 4 The type or namespace name 't' could not be found (are you missing a using directive or an assembly reference?)
Thanks
Hi Marjon
Thanks for the help.
I've put the change in, and I get the following errors
Error 1 'T' is a 'type parameter' but is used like a 'variable'
Error 2 The best overloaded method match for 'Csla.SortedBindingList<C>.SortedBindingList(System.Collections.Generic.IList<C>)' has some invalid arguments
Error 3 Argument '1': cannot convert from 'object' to 'System.Collections.Generic.IList<C>'
I'm passing in :
LoadData1<QL.View.
ClientList, QL.View.ClientInfo>(parameterValues);Thanks Marjon, that compiled for me too.
But I'm still having problems relating to 'typeof(T).GetMethod("GetList", ', it' doesn't find the method and factoryMethod therefore is null. I did GetMethods and looped through all the methods and it was there!
Maybe something to do with namespaces.
Thanks Marjon for the hand.
I just wanted to post what finally worked for completeness.
LoadData1<ClientList, ClientInfo>(parameterValues);
public void LoadData1<T, C>(object[] parms) where T : Csla.ReadOnlyListBase<T, C>
{
Type t = typeof(T);
MethodInfo methodInfo = t.GetMethod("GetList", System.Reflection.BindingFlags.Static | BindingFlags.Public);
T tmpList = (T)(methodInfo.Invoke(null, parms));
Csla.SortedBindingList<C> sortedList = new Csla.SortedBindingList<C>(tmpList);
this.resultsDataGridView.DataSource = sortedList;
}
Copyright (c) Marimer LLC