zoukankan      html  css  js  c++  java
  • WPF listbox分页

            List<ListBoxItem> llb;//符合条件像的listbox数据集合
          public static List<ModelDataBase> datalist = new List<ModelDataBase>();//总的数据源
          int pageIndex = 1;//当前页
          int pageSize = 16;//一页最大容量
          int totalPage = 0;//总页数
    
          public void TakePage()
            {
                tbindex.Text = pageIndex.ToString();
                listBox.ItemsSource = llb.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            }
    
    //首页
          private void btnFirst_Click(object sender, RoutedEventArgs e)
            {
                pageIndex = 1;
                TakePage();
            }
    
            //尾页
          private void btnLast_Click(object sender, RoutedEventArgs e)
            {
                pageIndex = totalPage;
                TakePage();
            }
    
            //上一页
          private void btnPrev_Click(object sender, RoutedEventArgs e)
            {
                if (pageIndex > 1)
                {
                    pageIndex -= 1; TakePage();
                }
            }
    
            //下一页
          private void btnNext_Click(object sender, RoutedEventArgs e)
            {
                if (pageIndex < totalPage)
                {
                    pageIndex += 1;
                    TakePage();
                }
            }
    
    public List<ListBoxItem> BoundData(int _pageIndex, int _pageSize, string strString,string sign)
            {
                llb = new List<ListBoxItem>();
                List<ModelDataBase> listmodel = null;
                if (sign.Equals("1"))
                {
                    listmodel = datalist.FindAll(item => (int)item._ParentID == Convert.ToInt64(strString));
                }
                else if (sign.Equals("0"))
                {
                    listmodel = datalist.Where(s => s._ModelName.Contains(strString)).ToList();
                }
                else
                {
                    listmodel = datalist.Where(s => s._ModelName == strString).ToList();
                }
                foreach (ModelDataBase item in listmodel)
                {
                    ListBoxItem lbi = new ListBoxItem();
                    lbi.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                    StackPanel sp = new StackPanel();
                    Image img = new Image();
                    string url = item._ModelURL;
                    img.Source = new BitmapImage(new Uri(@url, UriKind.Relative));
                    System.Windows.Controls.Label lable = new System.Windows.Controls.Label();
                    lable.Content = item._ModelName;
                    sp.Children.Add(img);
                    sp.Children.Add(lable);
                    sp.Tag = item._MidelRemark;
                    lbi.Content = sp;
                    lbi.MouseDoubleClick += Lbi_MouseDoubleClick;
                    llb.Add(lbi);
                }
                //初始化分页元素
                pageIndex = 1;
                tbindex.Text = pageIndex.ToString();
                int count = listmodel.Count;//总数据条数
                if (count % pageSize == 0)
                {
                    totalPage = count / pageSize;
                }
                else
                {
                    totalPage = count / pageSize + 1;
                }
                tbmax.Text = totalPage.ToString();
                DisableClick(true);
                return llb.Skip(0).Take(pageSize).ToList();
            }
    
  • 相关阅读:
    网络通信过程
    路由表转发分析实例
    随机生成MAC地址和IP地址
    zabbix监控LAMP全教程
    linux ssh利用公钥免密登陆
    如果Mysql插入字符始终乱码怎么办?
    Windows 桌面利用 Navicat等工具连接 虚拟机Mysql
    pagefile.sys 虚拟内存
    linux常用命令---------------find
    当你使用Pycharm编译程序的时候,遇到了这个问题,该怎么办?please select a valid interpreter
  • 原文地址:https://www.cnblogs.com/chendongbky/p/6478262.html
Copyright © 2011-2022 走看看