Binding troubles

4 posts, 1 answers
  1. Alessio
    Alessio avatar
    2 posts
    Member since:
    Feb 2012

    Posted 02 Apr 2012 Link to this post

    I tried to follow your guide, but I'm not able to figure out what step I skipped... 
    The problem is that when I group my items, they all get into a single group with the FQDN of the object in BindingList. For the same reason (I think), the ordering doesn't work.

    I set up a RadListView whith those parameters (ViewType cannot be changed):
    radListView1.DataSource = dtoList;
    oDtoList = dtoList;
    radListView1.DisplayMember = "Title";
    radListView1.ValueMember = "PictureId";
    radListView1.ViewType = ListViewType.IconsView;
    radListView1.Padding = new Padding(10, 48, 10, 10);
    this.radListView1.ItemSize = new Size(300, 110);
    this.radListView1.ItemSpacing = 5;
    this.radListView1.AllowArbitraryItemHeight = false;

    dtoList is a BindingList of:
    public class DTOimage
        {
           public Int64 PictureId;
           public String Path;
           public String Author;
           public String Title;
           public DTOimage(){}
           public DTOimage(Int64 pictureId, String path, String author, String title)
           {
               PictureId = pictureId;
               Path = path;
               Author = author;
               Title = title;
           }
        }

    when I group items, I've:
    private void commandBarDropDownList2_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
            {
                this.radListView1.GroupDescriptors.Clear();
                switch (this.commandBarDropDownList2.Text)
                {
                    case "Nessuno":
                        this.radListView1.EnableGrouping = false;
                        this.radListView1.ShowGroups = false;
                        break;
                    case "Nome":
                        this.radListView1.GroupDescriptors.Add(new GroupDescriptor(
                            new SortDescriptor[] { new SortDescriptor("Title", ListSortDirection.Ascending) }));
                        this.radListView1.EnableGrouping = true;
                        this.radListView1.ShowGroups = true;
                        break;
                    case "Autore":
                        this.radListView1.GroupDescriptors.Add(new GroupDescriptor(
                            new SortDescriptor[] { new SortDescriptor("Author", ListSortDirection.Ascending) }));
                        this.radListView1.EnableGrouping = true;
                        this.radListView1.ShowGroups = true;
                        break;
                }
            }

  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 04 Apr 2012 Link to this post

    Hi Alessio,

    Thank you for writing.

    The observed behavior is caused by the fact that your data class does not have public properties, but public fields. If you change the definition of your DTOimage class as shown below, you should get this scenario working as expected:
    public class DTOimage
    {
        public Int64 PictureId { get; set; }
        public String Path { get; set; }
        public String Author { get; set; }
        public String Title { get; set; }
        public DTOimage() { }
        public DTOimage(Int64 pictureId, String path, String author, String title)
        {
            PictureId = pictureId;
            Path = path;
            Author = author;
            Title = title;
        }
    }

    The reason for this is that the data layer over which RadListView is built, takes into consideration only the public properties and not the fields. The same data layer is used in RadGridView and RadTreeView so this is also relevant for these controls.

    I hope this helps. Feel free to ask if you have any additional questions.

    Kind regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alessio
    Alessio avatar
    2 posts
    Member since:
    Feb 2012

    Posted 04 Apr 2012 Link to this post

    Whoa... Easy as you said, thank you.
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 04 Apr 2012 Link to this post

    Hi Alessio,

    You are welcome. Let us know if you have additional questions.

    Greetings,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top