public class Product
{
string name;
public string Name { get { return name; } }
double price;
public double Price { get { return price; } }
string location;
public string Location { get { return location; } }
public Product(string name, double price, string location)
{
this.name = name;
this.price = price;
this.location = location;
}
}
Now I created a list of Product object
List
new Product("WWW", 9.99, "ZZZZZZZZZ"),
new Product("AAA", 14.99, "RRRRRRRR"),
new Product("AAA", 12.99, "AAAAAAA"),
new Product("GGG", 13.69, "WWWWWWWWWWWWWWW"),
new Product("GGG", 13.99, "NNNNNNNN"),
new Product("KKK", 10.99, "TTTTTTTTTTTTTTTT")
};
Then, I need to sort them firstly by Name and then bind into a DataGrid.
Thanks in advance
Hemant SrivastavaPosted Jan 11, 2013, 7:02 PM
lstProduct.Sort((x, y) => x.Name.CompareTo(y.Name));
dataGridView1.DataSource = lstProduct;
Tulika KumarPosted Jan 11, 2013, 7:20 PM
VulpesPosted Jan 11, 2013, 6:46 PM
lstProduct = lstProduct.OrderBy(p => p.Name).ThenBy(p => p.Location).ToList();