如何对DevExpress图库控件项进行排序?

时间:2016-02-27 20:04:53

标签: c# sql sorting devexpress

我在我的图书馆程序中使用DevExpress GalleryControl。 但问题是我想在GalleryControl中对项目进行排序,我不知道如何做到这一点,我相信GalleryControl没有内置的功能来排序项目(不太确定)。

所以我的程序在数据库(SQL)中连接。

所以我想要发生这种情况,我希望按字母顺序或按作者或部门对其进行排序,为此我希望它为图库控件创建组,并且该组将包含属于它的项目。

你能帮帮我吗?

检查我做了什么:

public void LoadBooks(object state)
    {

       GalleryItemGroup group = new GalleryItemGroup();
       galleryControl1.Gallery.Groups.Add(group);
            group.Items.Clear();


            group.Caption = "All books";
            group.CaptionAlignment = GalleryItemGroupCaptionAlignment.Center;


        MySqlConnection connection = null;
        try
        {
            connection = new MySqlConnection(MyConnectionString);
            connection.Open();

            MySqlCommand cmd = connection.CreateCommand();
            //This is arrange by alphabetically but I want to create gallery groups for each letters and the group will contain every items that belongs to it.
            cmd.CommandText = "Select * from booktable ORDER BY booktitle";
            MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
            DataTable ds = new DataTable();
            adap.Fill(ds);



            Invoke(new Action(() =>
            {
                for (int i = 0; i < ds.Rows.Count; i++)
            {
                byte[] byteBLOBData = (byte[])ds.Rows[i]["bookphoto"];
                var stream = new MemoryStream(byteBLOBData);

                Image bookimages = Image.FromStream(stream);
                string author = ds.Rows[i]["bookauthor"].ToString();
                string title = ds.Rows[i]["booktitle"].ToString();



                    group.Items.Add(new GalleryItem(bookimages, title, author));
                    group.Items[i].HoverImage = group.Items[i].Image;

                }
            }));
        }
        finally
        {
            if (connection != null && connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }
    }

默认情况下,它按书本ID排序,这是我在SQL中的主键。 请有人帮助我,我会感激任何帮助。

顺便提一句,我是Stackoverflow的新手。很高兴来到这里。

0 个答案:

没有答案