c# - Linq group by to create nested listview -
i need create nested listview , found a great article on how it, situation bit different. linq newbie , need little please :)
i need data format similar in article work (on link above, search "configuring listview" , see table right above it).
here data:
format movie name price dvd star wars 12.99 dvd star wars ii 13.99 blue-ray star wars 15.99 blue-ray star wars ii 17.99 here have, isn't close, far get:
var moviestobuy = movie in dtmovielistdetails.asenumerable() //join moviedetails in dtmovielistdetails.asenumerable() on (string)movie["id"] equals (string)moviedetails["id"] group movie new { format = movie["format"], movies = movie } grp select new { format = (string)grp.key.format, movies = grp.key.movies }; moviestobuy = moviestobuy.orderby(p => p.format); lvwamazonmoviegroup.datasource = moviestobuy.tolist(); lvwamazonmoviegroup.databind(); i have 3 specific issues/questions:
1.) have doesn't work. since second column in group equates rows, no actual group created.
2.) despite prior issue, getting "data source invalid type. must either ilistsource, ienumerable, or idatasource" error. in case, movies column being created datarow datatype. not sure if creating problem. can cast on field somehow?
3.) how can sort on fields in movies. i.e. in end want data sorted format movie name nested list view looks this:
blue-ray star wars 12.99 star wars ii 13.99 dvd star wars 15.99 star wars ii 17.99 any points appreciated!
thanks in advance, chad
i thinking start following, adjusting proper variable names , asenumerable(), etc.
it orders movies want , puts them in nested structure requested:
var moviestobuy = movie in dtmovielistdetails orderby movie.format, movie.price group movie movie.format grp select new { format = grp.key, movies = grp.select (g => new { moviename = g.moviename, price = g.price }) };
Comments
Post a Comment