|
-
Aug 2nd, 2007, 05:04 AM
#1
Thread Starter
Fanatic Member
Generic Method Reutn Type
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile
Error 29 Cannot implicitly convert type 'System.Collections.Generic.List<Prsym.ComboPopulation.ComboInfo>' to 'System.Collections.Generic.List<T>
'
Code:
/// <summary>
/// Gets the data source to be bound to a ComboBox.
/// </summary>
/// <param name="storedProcedure">The Name of the Stored Procedure to be used.</param>
/// <param name="scheme">The scheme.</param>
/// <returns>A Generic List to be dound to a ComboBox</returns>
private static List<T> GetDataSource<T>(string storedProcedure, PrsymScheme scheme)
{
Type dataSourceListType = typeof(T);
if (dataSourceListType == typeof(ComboInfo)) {
List<ComboInfo> dataSourceList = new List<ComboInfo>();
ComboInfo datSourceComboInfo = new ComboInfo();
DataBaseAccess DBA = new DataBaseAccess(scheme);
SqlDataReader reader = null;
DBA.LoadData(ref reader, storedProcedure);
while (reader.Read()) {
datSourceComboInfo.Display = reader["Display"].ToString();
datSourceComboInfo.Index = Convert.ToInt32(reader["Index"].ToString());
dataSourceList.Add(datSourceComboInfo);
}
//Clean up
reader.Dispose();
System.Collections.ArrayList p = new System.Collections.ArrayList();
return dataSourceList;
} else {
return null;
}
}
Any help would be greatly received
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Aug 2nd, 2007, 06:26 AM
#2
Hyperactive Member
Re: Generic Method Reutn Type
By your original post title, I beleive the generic return method is object/Object, with the problem in your post, is there some sort of converter function from type 1 (System.Collections.Generic.List<Prsym.ComboPopulation.ComboInfo>) to type 2 (System.Collections.Generic.List<T>)?
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|