zk6中listbox设置了checkmark="true" multiple="true" 没用的问题

 

 大家用zk6有没有遇到listbox设置了checkmark="true" multiple="true" 运行后只显示radio不能显示checkbox的问题?

首先,请大家注意你的数据对象是ListModelList还是List,使用ListModelList是有原因的;
1.如果是ListModelList,那么请在new ListModelList之后
datas.setMultiple(true);
 
 如果直接使用的是List对象,则不用设置,checkbox是会显示的,但是两者都没有全选框。

2. [不建议使用]即使你设置以后你会发现,在listheader中的全选按钮没有了,这时如果我们还是自己实现一个全选功能的话,在listhead中添加代码:
<listhead width="100%">
	<listheader width="45px">
		<checkbox>
			<attribute name="onCheck">
				if (self.isChecked()) {
					lbx.selectAll();
				} else {
				lbx.clearSelection();
			}</attribute>
		  </checkbox>
	</listheader>
...
</listhead>
 即可解决checkbox不显示的问题。ok。

注意:如果这样做在zk6中实现的全选其实是5版本的功能,用在mvc的模式下是可以用,但对于6来说并没有意义,zk6没有全选是有原因的,它使用了ListModelList,在界面上逐个选择时可以触发事件,通知ListModelList,数据的选择状态被改变了,然后就可以在类中直接使用datas.getSelection()得到被选中的记录Set.所以从ZK6升级后listbox的这一改变来看,MVVM的设计模式正在逐步的演化,后面的版本定会更加的完善,可能会完成脱离MVC的设计模式,这样一来,冗余度将大大的降低。

3. [建议方法]那么应该如何解决这一问题呢,当然是通过注册一个事件来改变ListModelList的选择状态。

<listhead width="100%">
	<listheader width="45px">
			<checkbox onCheck="@command('selectAllOrCancel',var=self.checked)"/>
	</listheader>
...
</listhead>

 后台Java类:

@Command
@NotifyChange("datas")
public void selectAllOrCancel(@BindingParam("var") boolean checked) {
		if (checked)
			datas.setSelection(datas);
		else
			datas.clearSelection();
}
 
这时写一个测试方法就可以验证:

@Command
@NotifyChange({ "totalSize", "datas" })
public void activate() {
		for (User u : datas.getSelection()) {
			System.out.println(u.getName());
}
 
ok,感谢”未来之路”的对这个问题感兴趣。
如果您在将List绑定到List控件时遇到了错误,可能是因为List控件无法直接将List作为数据源。您可以尝试使用BindingSource作为间层来实现数据绑定。以下是修改后的代码示例: ```csharp using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace ListExample { public partial class MainForm : Form { private string connectionString = "YourConnectionString"; // 替换为您的数据库连接字符串 public MainForm() { InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { // 创建连接对象 using (SqlConnection connection = new SqlConnection(connectionString)) { // 创建查询语句 string query = "SELECT * FROM YourTableName"; // 替换为您的表名 // 打开数据库连接 connection.Open(); // 创建Command对象 SqlCommand command = new SqlCommand(query, connection); // 执行查询并获取DataReader对象 SqlDataReader reader = command.ExecuteReader(); // 创建一个List来存储数据 List<string> dataList = new List<string>(); // 读取数据并添加到List while (reader.Read()) { string data = reader["ColumnName"].ToString(); // 替换为您的列名 dataList.Add(data); } // 关闭DataReader reader.Close(); // 创建BindingSource对象,并将List作为数据源 BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dataList; // 将BindingSource绑定到List控件 listBox.DataSource = bindingSource; } } } } ``` 在这个示例,我们使用了BindingSource作为间层来将List作为数据源绑定到List控件。这样就可以解决直接将List绑定到List控件时的错误。如果问题仍然存在,请提供具体的错误信息,以便我能够更好地帮助您解决问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值