DevExpress LookUpEdit 行为

发布于 2024-08-20 23:10:52 字数 808 浏览 5 评论 0原文

我为这个令人惊奇的问题而抓狂。

我从代码中绑定 2 个 LookUpEdit:

            MyBinding.DataSource = typeof(MyObject);
        MyBinding.DataSource = _dataObject.GetMyList();

        firstLookUp.DataBindings.Add("EditValue", MyBinding, "Code");
        firstLookUp.Properties.DataSource = MyBinding;
        firstLookUp.Properties.ValueMember = "Code";
        firstLookUp.Properties.DisplayMember = "Code";

        secondLookUp.DataBindings.Add("EditValue", MyBinding, "Info");
        secondLookUp.Properties.DataSource = MyBinding;
        secondLookUp.Properties.ValueMember = "Info";
        secondLookUp.Properties.DisplayMember = "Info";

第一个问题是:更改两个 LookUp 之一的值并没有反映出另一个 LookUp 的更改!但是我使用相同的BindingSource,位置不一样吗?

另一个是:它们都自动填充列,我不想显示所有列,尝试删除,未找到异常列,如果我添加,我会得到重复的列! 我不明白!

I'm tearing my hair off for this amazing problem.

I'm binding 2 LookUpEdit from code:

            MyBinding.DataSource = typeof(MyObject);
        MyBinding.DataSource = _dataObject.GetMyList();

        firstLookUp.DataBindings.Add("EditValue", MyBinding, "Code");
        firstLookUp.Properties.DataSource = MyBinding;
        firstLookUp.Properties.ValueMember = "Code";
        firstLookUp.Properties.DisplayMember = "Code";

        secondLookUp.DataBindings.Add("EditValue", MyBinding, "Info");
        secondLookUp.Properties.DataSource = MyBinding;
        secondLookUp.Properties.ValueMember = "Info";
        secondLookUp.Properties.DisplayMember = "Info";

First problem is: Changing the value on one of the two LookUps not reflecting changing the other one! But im using the same BindingSource, isn't the position the same?

Another one is: They both populate automatically the columns, i dont want to show all columns, tried to remove, exception column not found, if i add, i get duplicate columns!
I don't get it!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风启觞 2024-08-27 23:10:52

更改 LookupEdit 的 EditValue 并不直接绑定到 BindingSource.Current 位置。

您必须使用类似的方法,

lookUpEdit1.Properties.GetDataSourceRowByKeyValue(lookUpEdit1.EditValue)

如果您希望链接两个 LookupEdits,则最好在另一个更改时设置一个的编辑值。

其次,您应该能够像这样清除列列表:

lookUpEdit1.Properties.Columns.Clear();
lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("FirstName"));

Changing LookupEdit's EditValue is not directly bound to the BindingSource.Current position.

You have to use something like

lookUpEdit1.Properties.GetDataSourceRowByKeyValue(lookUpEdit1.EditValue)

If you want both LookupEdits linked you are probably better off setting the edit value of the one when the other is changed.

Secondly You should be able to clear the list of Columns like so:

lookUpEdit1.Properties.Columns.Clear();
lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("FirstName"));
姜生凉生 2024-08-27 23:10:52

正如这里所说

http://www.devexpress.com/Support/Center/p /B138420.aspx

http://www.devexpress.com/ Support/Center/p/A2275.aspx

LookupEdit 确实会更新 BindingSource 的 Current 属性。

我们使用以下代码作为解决方法:

/// <summary>
/// Wrapper around DevExpress.XtraEditors.LookUpEdit to fix bug with adjusting the BindingSources Current Position
/// </summary>
public sealed class LookUpEditWithDataSource : LookUpEdit
{
    private bool firstCall = true;

    /// <summary>
    /// Called when the edit value changes.
    /// </summary>
    protected override void OnEditValueChanged()
    {
        base.OnEditValueChanged();

        if (this.Properties.DataSource == null)
        {
            return;
        }

        if (this.BindingContext == null)
        {
            return;
        }

        if (this.firstCall)
        {
            this.firstCall = false;

            // HACK
            // starting and selecting the first item
            // doesn't work so we change the position to the first item
            this.BindingContext[this.Properties.DataSource].Position = 1;
        }

        this.BindingContext[this.Properties.DataSource].Position = this.Properties.GetDataSourceRowIndex(this.Properties.ValueMember, this.EditValue);
    }
}

As said here

http://www.devexpress.com/Support/Center/p/B138420.aspx

http://www.devexpress.com/Support/Center/p/A2275.aspx

LookupEdit does update the Current Property of the BindingSource.

We use the following Code as a workaround:

/// <summary>
/// Wrapper around DevExpress.XtraEditors.LookUpEdit to fix bug with adjusting the BindingSources Current Position
/// </summary>
public sealed class LookUpEditWithDataSource : LookUpEdit
{
    private bool firstCall = true;

    /// <summary>
    /// Called when the edit value changes.
    /// </summary>
    protected override void OnEditValueChanged()
    {
        base.OnEditValueChanged();

        if (this.Properties.DataSource == null)
        {
            return;
        }

        if (this.BindingContext == null)
        {
            return;
        }

        if (this.firstCall)
        {
            this.firstCall = false;

            // HACK
            // starting and selecting the first item
            // doesn't work so we change the position to the first item
            this.BindingContext[this.Properties.DataSource].Position = 1;
        }

        this.BindingContext[this.Properties.DataSource].Position = this.Properties.GetDataSourceRowIndex(this.Properties.ValueMember, this.EditValue);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文