Click here to Skip to main content
15,887,135 members

Comments by User-15670402 (Top 10 by date)

User-15670402 4-Aug-22 12:28pm View    
This one:
SortableBindingList<ArtistList> xList = new SortableBindingList<ArtistList>();
xList = (from a in context.Artists
     orderby a.BirthName
     select new ArtistList
     {
          ArtistId = a.ArtistId,
          Last_Name = a.BirthName.Split(space).Last(),
          Age = DateTime.Today.Year - a.DateOfBirth.Year,
          Song_Count = a.Songs.Count
     }).ToList();

dgvArtists.DataSource = xList;
User-15670402 3-Aug-22 21:16pm View    
So I added the SortableBindingList class and then created a list.
SortableBindingList<ArtistList> xList = new SortableBindingList<ArtistList>();

Now my query is giving me an error that says: Cannot implicitly convert type 'System.Collections.Generic.List<final.artistlist>' to 'Final.SortableBindingList<final.artistlists>'
User-15670402 3-Aug-22 10:34am View    
Right I have this class and
List<ArtistList>
:
class ArtistList
    {
        public int ArtistId { get; set; }
        public string Last_Name { get; set; }
        public int Age { get; set; }
        public int Song_Count  { get; set; }
    }

I appreciate all your help! I did debug it and everything went smoothly until it reached the first case statement in:
private void dgvArtists_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvArtists.Columns[e.ColumnIndex].SortMode != DataGridViewColumnSortMode.NotSortable)
            {
                if (e.ColumnIndex == newSortColumn)
                {
                    if (newColumnDirection == ListSortDirection.Ascending)
                        newColumnDirection = ListSortDirection.Descending;
                    else
                        newColumnDirection = ListSortDirection.Ascending;
                }

                newSortColumn = e.ColumnIndex;

                switch (newColumnDirection)
                {
                    case ListSortDirection.Ascending:
                        dgvArtists.Sort(dgvArtists.Columns[newSortColumn], ListSortDirection.Ascending);
                        break;
                    case ListSortDirection.Descending:
                        dgvArtists.Sort(dgvArtists.Columns[newSortColumn], ListSortDirection.Descending);
                        break;
                }
            }
        }
    }
User-15670402 3-Aug-22 9:46am View    
When I changed it IList I'm getting the error "Cannot create an instance of the abstract class or interface 'interface'"

IList<ArtistList> xList = new IList<ArtistList>();


I just don't get what else I can do.
User-15670402 3-Aug-22 9:03am View    
I believe I did that, created a strongly typed object when I created the ArtistList class, correct? It still gives me the IBindingList error.
class ArtistList
    {
        public int ArtistId { get; set; }
        public string Last_Name { get; set; }
        public int Age { get; set; }
        public int Song_Count  { get; set; }
    }
List<artistlist> xList = new List<artistlist>();

            xList = (from a in context.Artists
                orderby a.BirthName
                select new ArtistList
                {
                    ArtistId = a.ArtistId,
                    Last_Name = a.BirthName.Split(space).Last(),
                    Age = a.DateOfDeath.HasValue ?
                        (Convert.ToDateTime(a.DateOfDeath).Year - a.DateOfBirth.Year) :
                        (DateTime.Today.Year - a.DateOfBirth.Year),
                    Song_Count = a.Songs.Count

                }).ToList();

            dgvArtists.DataSource = xList;