Using LINQ for Listboxes
Recently I blogged about how shitty multi-select listboxes are in winforms.
Well, pulling your data out using LINQ as a datasouce is much less painful. Simply throw something like this into your PageLoad
this.listBox1.DataSource = db.tGuilds.OrderBy(g => g.GuildName);
this.listBox1.ValueMember = “GuildGameID”;
this.listBox1.DisplayMember = “GuildName”;
//and when you want to get the selected items back out you can grab them typed without all that nasty casting rubbish of old.
List<int> guildIDs = new List<int>();
//The tGuild below would have been a type object before
foreach (tGuild selection in listBox1.SelectedItems)
guildIDs.Add(selection.GuildGameID); //Instead of
//DataRowView drv = (DataRowView)selection;