ZK ListBox 的延迟加载的解决

使用了 Listbox 控件, setModel 方式绑定数据, 但是发现, 在滚动中出现了数据加载的延迟现象。 这个效果可能不能接受。

 

 

<listbox id="searchResult"  height="500px" fixedLayout="true" >
	<listhead sizable="false" height="20px">
		<listheader  label="选择" align="left" width="45px"/>
		<listheader  label="工号" align="left"/>
		<listheader  label="姓名" align="left"/>
		<listheader  label="单位" align="left"/>
		<listheader  label="机型" align="left"/>
		<listheader  label="教员标准" align="left"/>
		<listheader  label="检查员标准" align="left" width="85px"/>
	</listhead><!-- 
	<listitem  height="20px"    forEachBegin="1" self="@{each='pilotBasicInfor'}" value="@{pilotBasicInfor}">

		<listcell ><radio value="@{pilotBasicInfor.basicInfoId}" radiogroup="choosePilotInfor" onCheck="controller.pilotInforOnSelect(self)" ></radio></listcell>
		<listcell label="@{pilotBasicInfor.clerkCode}" />
		<listcell>
			<a label="@{pilotBasicInfor.pilotName}"/>
		</listcell>
		<listcell label="@{pilotBasicInfor.unitName}" />
		<listcell
			label="@{pilotBasicInfor.acTypeName}" />
		<listcell label="@{pilotBasicInfor.teacherTypeName}" />
		<listcell label="@{pilotBasicInfor.inspectorTypeName}" />
	</listitem> -->
</listbox>

 

 

 注释了上面的绑定代码,

 

 

采用了在 Java  中创建组建添加到 ListBox 中的方式 , 解决了这个延迟的问题 。 代码:

 

 

 

OrderablePagination orderablePagination = new OrderablePagination(0, 0, 0);
orderablePagination.setTotalCount(0);
listPiv = (List<PeopleDto>) this.executeQuery(orderablePagination);
Listbox listResult = (Listbox) self.getFellowIfAny("searchResult");
listResult.getItems().clear();
listResult.setCheckmark(true);
listResult.setMultiple(false);
for(PeopleDto p : listPiv){
	System.out.println("-------------"+p.getPilotName());
//			if(i == 10)
//				break;
	final Listitem li = new Listitem();
	li.setParent(listResult);
	li.setValue(p.getBasicInfoId().toString());
	li.addEventListener(Events.ON_CLICK, new EventListener() {
		
		@Override
		public void onEvent(Event arg0) throws Exception {
			// TODO Auto-generated method stub
			checkedBasicInforID = new Long(li.getValue().toString());
		}
	});
	Listcell cell = new Listcell();
	li.appendChild(cell);
	li.appendChild(new Listcell(p.getClerkCode()));
	li.appendChild(new Listcell(p.getPilotName()));
	li.appendChild(new Listcell(p.getUnitName()));
	li.appendChild(new Listcell(p.getAcTypeName()));
	li.appendChild(new Listcell(p.getTeacherTypeName()));
	li.appendChild(new Listcell(p.getInspectorTypeName()));
//			i++;
}

 

 

 

但是, 每次查询的时候, 旧的数据不能清空, 需要手动调用方法:

 

注意此处调用的代码 :

 

listResult.getItems().clear();

 

ListBox  中的 ListHead  不会被清除, 但是加载的 ListItem  会被清空。 。

 

然后加载数据 。

 

listResult.setCheckmark(true);
listResult.setMultiple(false);

 

设置成为 单选列表。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现WinForm中ListBox的分页加载,可以按照以下步骤进行: 1. 在设计窗体时,添加一个ListBox控件,并设置其Dock属性为Fill,以填充整个窗体。 2. 在窗体的Load事件中,初始化ListBox控件的第一页数据,并将其绑定到ListBox中。这可以通过数据访问层(如ADO.NET)或业务逻辑层来实现。 3. 添加两个Button控件,一个用于加载上一页数据,一个用于加载下一页数据。在这两个控件的Click事件中,根据当前页码和每页显示的数据条数,计算出需要加载的数据的起始位置和结束位置,并重新绑定到ListBox中。 4. 可以添加一个Label控件,显示当前页码和总页数,以及一个ComboBox控件,用于选择每页显示的数据条数。 5. 在分页加载数据时,需要注意处理数据为空或数据不足一页时的情况,以及加载过程中的进度提示。 下面是一个简单的示例代码: ``` public partial class Form1 : Form { private int pageSize = 10; private int currentPage = 1; private List<string> dataList = new List<string>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // 初始化数据 for (int i = 0; i < 100; i++) { dataList.Add("Item " + i); } // 绑定第一页数据 BindData(); } private void BindData() { int startIndex = (currentPage - 1) * pageSize; int endIndex = startIndex + pageSize - 1; if (endIndex >= dataList.Count) { endIndex = dataList.Count - 1; } listBox1.DataSource = dataList.GetRange(startIndex, endIndex - startIndex + 1); UpdatePageInfo(); } private void UpdatePageInfo() { int pageCount = (int)Math.Ceiling((double)dataList.Count / pageSize); label1.Text = string.Format("Page {0}/{1}", currentPage, pageCount); } private void buttonPrev_Click(object sender, EventArgs e) { if (currentPage > 1) { currentPage--; BindData(); } } private void buttonNext_Click(object sender, EventArgs e) { int pageCount = (int)Math.Ceiling((double)dataList.Count / pageSize); if (currentPage < pageCount) { currentPage++; BindData(); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { pageSize = int.Parse(comboBox1.SelectedItem.ToString()); currentPage = 1; BindData(); } } ``` 注意:此示例代码只是一个初步的实现,还有许多细节需要处理,例如数据为空时的提示、数据不足一页时的处理、加载过程中的进度提示等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值