Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
List<sfdclistinfo> IstsfdcInfo = new List<sfdclistinfo>();


i need to return the list if it contains data and bind them to datagridview

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 2-Apr-15 0:30am
v3
Comments
Mehdi Gholam 2-Apr-15 5:48am    
A list of what and to where?
StM0n 2-Apr-15 5:49am    
One List to bind them all ;)
Andy Lanng 2-Apr-15 6:21am    
Rofl ^_^
StM0n 2-Apr-15 5:49am    
Are you aware of the fact, that there's no List-Class... only the generic List<t>?
Sinisa Hajnal 2-Apr-15 6:11am    
What have you tried? Returning the list from where? Please clarify.

First:

List are a generic type. In other words they must be a list of something. You need to tell it what that something is:
C#
//List<t> list = new List<t>() where T is a Type.

List<int> intList = new List<int>(); //a List of integers

intList.Add(1);  // add integer to the list
intList.Add(256);

if(intList.Any()) // a linq way of saying intList.Count()>0
 Console.WriteLine(intList.Count());

//out:> 2


The list Type can be any type. I used a primitive here but they are often used for storing complex and user defined types.

Alternatives to List include, but are not limited to:

C#
//Array
int[] intArray = new int[2]; // creates an array of ints but it has a fixed size (2).
//Dictionary
Dictionary<int,string> = new Dictionary<int,string>(); //very different usage.
This type stores a key(int) that is used to access its value(string).

All of these collections are generic and cannot be instanciated without being specified with a type (ok, so Arrays are a little different but the still must be typed).

For more information on generics please see this link
An Example of Generics Using C# in ASP.NET[^]
 
Share this answer
 
v4
That list won't contain data - it just creates a new, empty list.
If you want to add items to it (from some source) then it's very, very easy to use it with a DataGridView:
C#
public class ProdTotalSales
    {
    public string Text { get; set; }
    public int Value { get; set; }
    private string Hidden { get; set; }
    public ProdTotalSales(string s, string h, int i)
        {
        Text = s;
        Hidden = h;
        Value = i;
        }
    }

C#
ProdTotalSales p1 = new ProdTotalSales("P1", "p1 hidden", 1);
ProdTotalSales p2 = new ProdTotalSales("P2", "p2 hidden", 2);
List<prodtotalsales> list = new List<prodtotalsales>() { p1, p2 };
myDataGridView.DataSource = list;

Will give you a DataGridView with two columns (one for each public property in the class) and two rows (one for each instance of the class in the List).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900