Create & Bind Structured Database To ListView C# Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Add item to Listview controlHow do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Deleting youngest student's row in each group of ListView control
In musical terms, what properties are varied by the human voice to produce different words / syllables?
Is CEO the "profession" with the most psychopaths?
Is it fair for a professor to grade us on the possession of past papers?
What does it mean that physics no longer uses mechanical models to describe phenomena?
Where is the Data Import Wizard Error Log
Why can't I install Tomboy in Ubuntu Mate 19.04?
How to pronounce 伝統色
Drawing spherical mirrors
A letter with no particular backstory
Google .dev domain strangely redirects to https
Draw 4 of the same figure in the same tikzpicture
What is "gratricide"?
How to run automated tests after each commit?
Putting class ranking in CV, but against dept guidelines
Semigroups with no morphisms between them
The Nth Gryphon Number
Can a Beast Master ranger change beast companions?
What order were files/directories output in dir?
Is it possible to force a specific program to remain in memory after closing it?
Why are my pictures showing a dark band on one edge?
How many morphisms from 1 to 1+1 can there be?
Sliceness of knots
What initially awakened the Balrog?
Did any compiler fully use 80-bit floating point?
Create & Bind Structured Database To ListView C#
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Add item to Listview controlHow do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Deleting youngest student's row in each group of ListView control
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to delete all items in ListView1 except youngest student in each group by comparing their date of births.
So, I tried to create a structured database and binding it to my ListView1 but failed with errors & exceptions.
Any help is greatly appreciated.
This is my code-
// assume 'Students is a List<Student>
IEnumerable<Student> earlydatestudents = Students.GroupBy(std => std.Group)
.Select(grp =>
DateTime dt = grp.Min(s => s.DOB);
return grp.Where(st => st.DOB == dt);
)
.SelectMany(slist => slist);
var toDeleteList = Students.Except(earlydatestudents).ToList();
//
My ListView1 contains-
Student , DOB , Location
Group1
AAA 10-05-2000 Mumbai
BBB 05-02-2000 Pune
CCC 01-01-2000 Delhi
Group2
DDD 20-03-1999 Lucknow
EEE 15-06-1999 Chennai
FFF 18-09-1999 Ahmedabad
c#
add a comment |
I want to delete all items in ListView1 except youngest student in each group by comparing their date of births.
So, I tried to create a structured database and binding it to my ListView1 but failed with errors & exceptions.
Any help is greatly appreciated.
This is my code-
// assume 'Students is a List<Student>
IEnumerable<Student> earlydatestudents = Students.GroupBy(std => std.Group)
.Select(grp =>
DateTime dt = grp.Min(s => s.DOB);
return grp.Where(st => st.DOB == dt);
)
.SelectMany(slist => slist);
var toDeleteList = Students.Except(earlydatestudents).ToList();
//
My ListView1 contains-
Student , DOB , Location
Group1
AAA 10-05-2000 Mumbai
BBB 05-02-2000 Pune
CCC 01-01-2000 Delhi
Group2
DDD 20-03-1999 Lucknow
EEE 15-06-1999 Chennai
FFF 18-09-1999 Ahmedabad
c#
add a comment |
I want to delete all items in ListView1 except youngest student in each group by comparing their date of births.
So, I tried to create a structured database and binding it to my ListView1 but failed with errors & exceptions.
Any help is greatly appreciated.
This is my code-
// assume 'Students is a List<Student>
IEnumerable<Student> earlydatestudents = Students.GroupBy(std => std.Group)
.Select(grp =>
DateTime dt = grp.Min(s => s.DOB);
return grp.Where(st => st.DOB == dt);
)
.SelectMany(slist => slist);
var toDeleteList = Students.Except(earlydatestudents).ToList();
//
My ListView1 contains-
Student , DOB , Location
Group1
AAA 10-05-2000 Mumbai
BBB 05-02-2000 Pune
CCC 01-01-2000 Delhi
Group2
DDD 20-03-1999 Lucknow
EEE 15-06-1999 Chennai
FFF 18-09-1999 Ahmedabad
c#
I want to delete all items in ListView1 except youngest student in each group by comparing their date of births.
So, I tried to create a structured database and binding it to my ListView1 but failed with errors & exceptions.
Any help is greatly appreciated.
This is my code-
// assume 'Students is a List<Student>
IEnumerable<Student> earlydatestudents = Students.GroupBy(std => std.Group)
.Select(grp =>
DateTime dt = grp.Min(s => s.DOB);
return grp.Where(st => st.DOB == dt);
)
.SelectMany(slist => slist);
var toDeleteList = Students.Except(earlydatestudents).ToList();
//
My ListView1 contains-
Student , DOB , Location
Group1
AAA 10-05-2000 Mumbai
BBB 05-02-2000 Pune
CCC 01-01-2000 Delhi
Group2
DDD 20-03-1999 Lucknow
EEE 15-06-1999 Chennai
FFF 18-09-1999 Ahmedabad
c#
c#
asked Mar 22 at 10:54
DutanerDutaner
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication106
class Program
static void Main(string[] args)
List<Student> students = new List<Student>()
new Student() name = "AAA", dob = DateTime.ParseExact("10-05-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Mumbai",
new Student() name = "BBB", dob = DateTime.ParseExact("05-02-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Pune",
new Student() name = "CCC", dob = DateTime.ParseExact("01-01-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Delhi",
new Student() name = "DDD", dob = DateTime.ParseExact("20-03-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Lucknow",
new Student() name = "EEE", dob = DateTime.ParseExact("15-06-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Chennai",
new Student() name = "FFF", dob = DateTime.ParseExact("18-09-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Ahmedabad"
;
var results = students.OrderByDescending(x => x.dob) //sort from youngest to oldest
.GroupBy(x => x.dob.Year) //group by year
.Select(x => x.First()) //get first student born each year which is youngest
.ToList();
public class Student
public DateTime dob get; set;
public string name get; set;
public string location get; set;
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298093%2fcreate-bind-structured-database-to-listview-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication106
class Program
static void Main(string[] args)
List<Student> students = new List<Student>()
new Student() name = "AAA", dob = DateTime.ParseExact("10-05-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Mumbai",
new Student() name = "BBB", dob = DateTime.ParseExact("05-02-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Pune",
new Student() name = "CCC", dob = DateTime.ParseExact("01-01-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Delhi",
new Student() name = "DDD", dob = DateTime.ParseExact("20-03-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Lucknow",
new Student() name = "EEE", dob = DateTime.ParseExact("15-06-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Chennai",
new Student() name = "FFF", dob = DateTime.ParseExact("18-09-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Ahmedabad"
;
var results = students.OrderByDescending(x => x.dob) //sort from youngest to oldest
.GroupBy(x => x.dob.Year) //group by year
.Select(x => x.First()) //get first student born each year which is youngest
.ToList();
public class Student
public DateTime dob get; set;
public string name get; set;
public string location get; set;
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
add a comment |
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication106
class Program
static void Main(string[] args)
List<Student> students = new List<Student>()
new Student() name = "AAA", dob = DateTime.ParseExact("10-05-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Mumbai",
new Student() name = "BBB", dob = DateTime.ParseExact("05-02-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Pune",
new Student() name = "CCC", dob = DateTime.ParseExact("01-01-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Delhi",
new Student() name = "DDD", dob = DateTime.ParseExact("20-03-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Lucknow",
new Student() name = "EEE", dob = DateTime.ParseExact("15-06-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Chennai",
new Student() name = "FFF", dob = DateTime.ParseExact("18-09-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Ahmedabad"
;
var results = students.OrderByDescending(x => x.dob) //sort from youngest to oldest
.GroupBy(x => x.dob.Year) //group by year
.Select(x => x.First()) //get first student born each year which is youngest
.ToList();
public class Student
public DateTime dob get; set;
public string name get; set;
public string location get; set;
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
add a comment |
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication106
class Program
static void Main(string[] args)
List<Student> students = new List<Student>()
new Student() name = "AAA", dob = DateTime.ParseExact("10-05-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Mumbai",
new Student() name = "BBB", dob = DateTime.ParseExact("05-02-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Pune",
new Student() name = "CCC", dob = DateTime.ParseExact("01-01-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Delhi",
new Student() name = "DDD", dob = DateTime.ParseExact("20-03-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Lucknow",
new Student() name = "EEE", dob = DateTime.ParseExact("15-06-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Chennai",
new Student() name = "FFF", dob = DateTime.ParseExact("18-09-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Ahmedabad"
;
var results = students.OrderByDescending(x => x.dob) //sort from youngest to oldest
.GroupBy(x => x.dob.Year) //group by year
.Select(x => x.First()) //get first student born each year which is youngest
.ToList();
public class Student
public DateTime dob get; set;
public string name get; set;
public string location get; set;
Try following :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication106
class Program
static void Main(string[] args)
List<Student> students = new List<Student>()
new Student() name = "AAA", dob = DateTime.ParseExact("10-05-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Mumbai",
new Student() name = "BBB", dob = DateTime.ParseExact("05-02-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Pune",
new Student() name = "CCC", dob = DateTime.ParseExact("01-01-2000", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Delhi",
new Student() name = "DDD", dob = DateTime.ParseExact("20-03-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Lucknow",
new Student() name = "EEE", dob = DateTime.ParseExact("15-06-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Chennai",
new Student() name = "FFF", dob = DateTime.ParseExact("18-09-1999", "dd-MM-yyyy", CultureInfo.InvariantCulture), location = "Ahmedabad"
;
var results = students.OrderByDescending(x => x.dob) //sort from youngest to oldest
.GroupBy(x => x.dob.Year) //group by year
.Select(x => x.First()) //get first student born each year which is youngest
.ToList();
public class Student
public DateTime dob get; set;
public string name get; set;
public string location get; set;
answered Mar 22 at 12:31
jdwengjdweng
18.3k2917
18.3k2917
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
add a comment |
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
Thanks for your reply, Jdweng. When I imported the results variable into ListView1, it results in Nil value. listView1.Items.Clear(); int counterOfArraylist = results.Count; string[] str = new string[counterOfArraylist]; for (int i = 0; i < str.Length; i++) str[i] = results[i].ToString(); listView1.Items.Add(new ListViewItem(str));
– Dutaner
Mar 23 at 3:40
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
You have to use AddRange instead of Add when putting more than one item into a list. You can't do following : listView1.Items.Add(new ListViewItem(str)); See : stackoverflow.com/questions/9951704/…
– jdweng
Mar 23 at 8:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298093%2fcreate-bind-structured-database-to-listview-c-sharp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown