Hello,
I am trying to do a simple thing, which is get the table from sql using linq and import it to listview, its just the same as my other one previously that i made with windows app but this time i am using wpf/html with C#, so mainly using wpf for gui, and C# for coding, the problem is, its a little different, for example, i try and group all the info together using listviewitem, but when i use that, i dont get the same properties, for example when i do in windows form:
this works fine above, however for wpf or xaml, it doesnt when i try to do listviewitem, then do lv.teee.... wheres the TEXT!!!?? nothing, with my code that i attached (actaully i attached the entire project) includnig the sql database and error picture i get (screen shot), hope that helps, but again this is just to populate the listview with all the data in the sql database table, but having trouble with wpf, let me know if this makes sense to everyoneCode:listviewitem lv = new listviewitem(); lv.Text = blah blah; lv.subitem.add(more blah);
Thanks in advance, i will try and figureitout on my part as well
also i will be writing a tutorial onthe other stuff with windows apps, but since this is my birthday today, i will be busy this weekend![]()
Its only funny till someone gets hurt.... THEN ITS HILARIOUS
I am a bit lost. Well, at first sight I noticed you are trying to display a HashSet within Listview items. I am not sure is this even possible. But we have a bigger problem...
I started to comment in/out parts of the code, until I found the line that causes the exception. It is the foreach loop. Code below does not work, but disabling foreach does the trick.Code:HashSet<usergroup> group = new HashSet<usergroup>(); ///... group.Add(users); Listview1.Items.Add(group);
Code:foreach (var peeps in queryResults) { //usergroup users = new usergroup(peeps.FirstN, peeps.LastN, peeps.JobT); ////users.firstname = peeps.FirstN; ////users.lastname = peeps.LastN; ////users.jobtitle = peeps.JobT; //group.Add(users); //Listview1.Items.Add(group); //Listview1.Items.Add(peeps.FirstN.ToString()); ////lv.Text = peeps.FirstN; ////lv.SubItems.Add(peeps.LastN); ////lv.SubItems.Add(peeps.JobT); ////listView1.Items.Add(lv); }
proudly presenting my personal website and game website: F1Simulation. a thrilling Managed DirectX racing game... also my Ask Me
look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions
Thanks Arek for the discovery, dang, never would have thought it would be the foreach loop, but thats a great tip which i should have done, process of elimination, just wondering what should i do then... any advice instead of using the foreach loop or dont use the hashset, if not, since i cant use listviewitem, what class should i use?
Its only funny till someone gets hurt.... THEN ITS HILARIOUS
Hello,
Still trying to figure out how to get this wpf web app working, not sure why the foreach is not working... dont know, any ideas. here is the code that is no working
Code:public void querytable() { var queryResults = from c in db.tblUsers select new { FirstN = c.First_Name, LastN = c.Last_Name, JobT = c.Job_Title }; foreach (var u in queryResults) { usergroup users = new usergroup(u.FirstN, u.LastN, u.JobT); group1.Add(users); Listview1.Items.Add(group1); } }
Its only funny till someone gets hurt.... THEN ITS HILARIOUS
ahhhh still cant get it, any other ideas, i tried bindinglist but that is no success, i know it has to be the foreach, but what else i could i use besides foreach to make this dumb thing work??
here is the code with the bindinglist instead of list or other sorts:
any ideas please i am open to getting this dumb wpf web app done and workingCode:tbluserDataContext db = new tbluserDataContext(); BindingList<usergroup> group = new BindingList<usergroup>(); public void querytable() { var queryResults = from c in db.tblUsers select new { FirstN = c.First_Name, LastN = c.Last_Name, JobT = c.Job_Title }; foreach (var u in queryResults) { usergroup users = new usergroup(u.FirstN, u.LastN, u.JobT); group.Add(users); Listview1.Items.Add(group); } }
thanks all i will still try and get this dumb thing working even if it takes me aaaalll weeekendbut input and suggestions please or resolution would be great
Its only funny till someone gets hurt.... THEN ITS HILARIOUS
Yare yare, this topic is a real nut to crack. Lets regroup our forces and thoughts. Objective A: Fix the foreach loop, or even replace it. If you need to replace the query above too, then do so. I just can't figure this out.
I found Scott Gu's blog about LINQ, and took a query. Dunno if it works any better then current query, just a hint. Maybe make a query like this, and then try foreach?
![]()
proudly presenting my personal website and game website: F1Simulation. a thrilling Managed DirectX racing game... also my Ask Me
look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks