绑定列表在WinForm应用程序中继器 [英] Binding a List to Repeater in WinForm application

查看:135
本文介绍了绑定列表在WinForm应用程序中继器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始这个问题。建议的方法是使用一个的DataRepeater

I recently started this question. The suggested approach was to use a DataRepeater.

我已经看到了很多关于如何中继器绑定的例子,但他们都是为ASP,而不是Windows窗体应用程序。

I've seen a lot of examples on how to bind the repeater, but all of them were for ASP, not Windows Form applications.

我已经加入标签图片框按钮组件的模板,但我一直没能成功绑定我的的IList< SomeObject> 我的的DataRepeater

I have added Label, PictureBox and Button components to the template, but I've not been able to successfully bind my IList<SomeObject> to my DataRepeater.

我想填充这些部件从一个列表信息。

I'd like to populate those components with information from a list.

如何绑定的IList&LT; SomeObject&GT; DatarRepeater 中的WinForm应用

How to bind a IList<SomeObject> to a DatarRepeater in WinForm applications?

推荐答案

终于得到了它的工作!对于未来的参考,这是我用什么:

Finally got it working! For future reference, this is what I used:

首先调用此方法,用来初始化手工绑定,使用的BindingSource

First call this method to initilize manual binding, using a BindingSource:

private BindingSource bindingSource ;
private void InitUserListArea()
{
    _bindingSource = new BindingSource();
    _bindingSource.DataSource = tempUsers;
    _labelUserListRoleValue.DataBindings.Add("Text", _bindingSource, "Role");
    _labelUserListNameValue.DataBindings.Add("Text", _bindingSource, "Name");
    _labelUserListLastAccessValue.DataBindings.Add("Text", _bindingSource, "LastAccess");
    _dataRepeaterUserList.DataSource = _bindingSource;
}

然后获取数据(在我的情况下,从一个Web服务),并用数据填充列表。列表之后被填充时,或当任何改变occurr:

Then get data (in my case from a webservice) and fill the list with data. After the list is populated, or when any changes occurr:

private void RefreshDataRepeater()
{
    if (_dataRepeaterUserList.InvokeRequired)
    {
        _dataRepeaterUserList.Invoke((Action)(() => { RefreshDataRepeater(); }));
        return;
    }

    _bindingSource.DataSource = null;
    _bindingSource.DataSource = tempUsers;
    _dataRepeaterUserList.DataSource = null;
    _dataRepeaterUserList.DataSource = _bindingSource;
    _dataRepeaterUserList.Refresh();
}

这篇关于绑定列表在WinForm应用程序中继器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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