一次遍历一个数组10个项目,并通过按下按钮添加到列表框 [英] iterating through an array 10 items at a time and adding to listbox through button press

查看:150
本文介绍了一次遍历一个数组10个项目,并通过按下按钮添加到列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已将图片添加到列表中.我想从列表中获取10个项目,以填充我的WPF列表框.我创建了下一个和上一个按钮.我已禁用列表框上的水平和垂直滚动条.我想在列表框中显示10个项目,当我单击下一步"按钮时,我希望列表框显示列表中的下10张图片.当我按上一个按钮时,我想查看列表中的前10个项目.我怎样才能做到这一点?请有人告诉我.

Hi
i have added picures to a List. I want to get 10 items from the list to populate my wpf list box. i have created a next and previous button. i have disabled the horizontal and vertical scrollbars on the listbox. I would like to display 10 items in the listbox and when i click the next button i would like the listbox to show the next 10 pictures from the list. When i press my previous button i would like to view previous 10 items in list. How can i achieve this? please can someone show me.

推荐答案

以下内容无疑需要进行一些调整,但应将其关闭:

The following will undoubtedly need some tweaking, but it should be close:

int m_itemCounter = 0;
bool TopOfList { get { return m_itemCounter == 0); } }
bool EndOfList { get { return m_itemCounter >= listBox.Items.Count; } }

private List<string> GetNItems(int count)
{
    List<string> results = new List<string>();
    int stop = Math.Min(count, this.listBox.Items.Count - m_itemCounter);
    for (int i = m_itemCounter; i < stop; i++)
    {
        results.Add(this.listBox.Items[i]);
    }
    m_itemCounter += stop;
    return results;
}


您可以作弊并拥有一个包含所有图片的隐藏控件,创建一个起始点变量以指向图片1,然后在该隐藏列表的另一个列表框1-10中显示,当用户单击下一步,将起点变量增加到11并显示11-20,依此类推,显然首先清除了listview.

我知道这很混乱,在被大火击落之前,我会道歉,这取决于我的目标受众.这是一种方法.
you could cheat and have a hidden control containing all pictures, create a start point variable to point to pic 1 then display in another listbox 1 - 10 of the hidden one, when user clicks next increase the start point variable to 11 and display 11-20 and so on, obviously clearing listview first.

I know it messy and I apologize before i get shot down in flames, depending on my target audience it would be one way.


这篇关于一次遍历一个数组10个项目,并通过按下按钮添加到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆