不同的超值会员,相同的控制

发布于 2024-07-24 09:21:12 字数 1428 浏览 4 评论 0原文

编辑1

我相信我的问题源于以下内容。 填充下拉部分的函数将显示成员设置为 CountyName。 然后,当我尝试设置 SelectedText 或 EditValue 时,如建议的那样,该函数仅返回它尝试与下拉列表 DisplayMember 中的内容匹配的 CountyID。 我需要它来将其与 ValueMember 列表中的某些内容相匹配。

使用以下内容我让它工作,但它是一个黑客,我非常感谢找到一个真正的解决方案。

lkuResidenceCounty.ItemIndex = Convert.ToInt32(row["ResidencyCountyID"].ToString());

原始帖子

我在会员表单上有一个查找框(DevExpress),我使用此代码从数据库填写可能的值 -->

        lkuResidenceCounty.Properties.DataSource = ConnectBLL.BLL.Person.CountyList();
        lkuResidenceCounty.Properties.PopulateColumns();
        lkuResidenceCounty.Properties.DisplayMember = "CountyName";
        lkuResidenceCounty.Properties.ValueMember = "CountyID";
        lkuResidenceCounty.Properties.Columns[0].Visible = false;
        lkuResidenceCounty.Properties.Columns[2].Visible = false;
        lkuResidenceCounty.Properties.Columns[3].Visible = false;

这工作得很好,因为 CountyName 按预期显示。

但是,当我尝试使用下面的内容加载该字段的现有成员值时,该值是从数据集中获取一行的函数的一部分 -->

lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();

我得到一个空白框。 我已单步执行代码,并为会员返回了正确的 ID。

不幸的是,填充下拉选项的存储过程从维护表中提取,其中包含“CountyName”和“CountyName”列。 “县ID”。 所以这是正确的。 不幸的是,用于加载特定人员当前县的存储过程从人员表中提取,其中有一列名为“ResidencyCountyID”。 之所以如此命名,是因为还有一个“ResponsibilityCountyID”列。

我需要一种让它们共存的方法,有什么解决方案吗?

谢谢!

Edit 1

I believe my problem stems from the following. The function that fills the dropdown portion sets the Display Member to the CountyName. Then when I try and set the SelectedText or EditValue, as has been suggested, that function only returns the CountyID which it try's to match to something in the DropDown list DisplayMember. I need it to match it to something in the ValueMember list.

Using the following I got it to work but it is a HACK and I'd greatly appreciate finding a real solution.

lkuResidenceCounty.ItemIndex = Convert.ToInt32(row["ResidencyCountyID"].ToString());

Original Post

I have a lookup box(DevExpress) on a member form that I fill the possible values in from the DB with this code -->

        lkuResidenceCounty.Properties.DataSource = ConnectBLL.BLL.Person.CountyList();
        lkuResidenceCounty.Properties.PopulateColumns();
        lkuResidenceCounty.Properties.DisplayMember = "CountyName";
        lkuResidenceCounty.Properties.ValueMember = "CountyID";
        lkuResidenceCounty.Properties.Columns[0].Visible = false;
        lkuResidenceCounty.Properties.Columns[2].Visible = false;
        lkuResidenceCounty.Properties.Columns[3].Visible = false;

This works just fine as the CountyName is displayed as expected.

However, When I try and load an existing member's value for this field using the below, which is part of a function that takes a row from the DataSet -->

lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();

I get a blank box. I have stepped through the code and the correct ID is being returned for the member.

Unfortunately the stored procedure to fill the dropdown options pulls from a Maintenance Table with the columns "CountyName" & "CountyID". So that is correct. Unfortunately, the stored procedure to load a specific person's current county pulls from the Person Table where there is a column called "ResidencyCountyID". It is so named because there is also a "ResponsibilityCountyID" column.

I need a way for them both to coexist, any solutions?

Thanks!

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

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

发布评论

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

评论(3

牵你的手,一向走下去 2024-07-31 09:21:12

DisplayMember 和 ValueMember 用于用可选值列表填充控件。 要设置填充的 LookUpEdit 控件的选定值,请设置其 EditValue 属性:

lkuResidenceCounty.EditValue = row["ResidencyCountyID"].ToString();

响应您的编辑:根据文档:

当前选定的行确定编辑器的编辑值和显示文本的值。 BaseEdit.EditValue 的值是从 RepositoryItemLookUpEditBase.ValueMember 字段获取的,而编辑框中显示的文本是从所选行的 RepositoryItemLookUpEditBase.DisplayMember 字段获取的。

当您更改 BaseEdit.EditValue 时,
编辑器找到并选择该行
谁的
RepositoryItemLookUpEditBase.ValueMember
字段包含新值。 文本
编辑框中的内容更改为反映
新选择的行。

我不使用这些控件,但在我看来,它不应该像您所描述的那样工作。 我认为 ToString() 是问题所在,因为 EditValue 接受一个对象,因此它可能需要一个 int 值。 尝试:

lkuResidenceCounty.EditValue = (int)row["ResidencyCountyID"];

DisplayMember and ValueMember are used to populate the control with the list of selectable values. To set the selected value of a populated LookUpEdit control, set its EditValue property:

lkuResidenceCounty.EditValue = row["ResidencyCountyID"].ToString();

In response to your edit: According to the documentation:

The currently selected row determines values for the editor's edit value and display text. The value for BaseEdit.EditValue is obtained from the RepositoryItemLookUpEditBase.ValueMember field, while the text to display in the edit box is obtained from the RepositoryItemLookUpEditBase.DisplayMember field of the selected row.

When you change BaseEdit.EditValue,
the editor locates and selects the row
whose
RepositoryItemLookUpEditBase.ValueMember
field contains the new value. The text
in the edit box is changed to reflect
the newly selected row.

I don't use these controls but it sounds to me that it shouldn't be working as you described. I think the ToString() is the problem because EditValue accepts an object so it's probably expecting an int for the value. Try:

lkuResidenceCounty.EditValue = (int)row["ResidencyCountyID"];
尝蛊 2024-07-31 09:21:12

ValueMember 属性告诉列表在设置 Value 属性时要从哪个字段中提取。 将 ValueMember 设置为“CountyID”后,当列表为数据绑定时,它会将所有列表项的值属性设置为其相关对象的 CountyID 字段。

因此,您不应该这样做:

lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();

只要

lkuResidenceCounty.Properties.ValueMember = "CountyID";

您正确识别了要进行数据绑定的字段,那就完全没问题。 一旦列表获得数据绑定,您应该会看到您期望的结果。

但是,查看您的代码后,您似乎与您的字段不匹配。 在一个地方您使用 ResidencyCountyID,而在另一地方您使用 CountyID。 这很可能是您困惑的根源。 找出实际的字段名称是什么,并确保将 ValueMember 设置为该名称。

更新

阅读您的评论后,您要查找的是 SelectedValue 属性。 SelectedValue 属性告诉列表将所选值强制为您提供的任何输入。

本质上,这里发生了两件事。 ValueMember 告诉列表使用数据源中的值,SelectedValue 告诉列表当前选择的值应该是什么。

The ValueMember property tells the list what field to pull from when setting the Value property. Once you've set the ValueMember to "CountyID", then when the list is Databound, it will set all the list items' value properties to their respect objects' CountyID fields.

Hence, you should not do:

lkuResidenceCounty.Properties.ValueMember = row["ResidencyCountyID"].ToString();

but rather

lkuResidenceCounty.Properties.ValueMember = "CountyID";

was perfectly fine, as long as you've correctly identified the field you're trying to databind. Once the list get's databound you should see the results you're expecting.

However, after looking at your code, it seems that you're mismatching your field. In one place you're using ResidencyCountyID and in another you're using CountyID. That is most likely your source of confusion. Figure out what the actual field name is and make sure you set the ValueMember to that.

UPDATE

After reading your comment, what your looking for is the SelectedValue property. The SelectedValue property tells the list to force the selected value to whatever input you give it.

Essentially you have two things going on here. ValueMember tells the list what to use as the value from your data source, and SelectedValue which tells the list what the currently selected value should be.

旧话新听 2024-07-31 09:21:12

为什么需要同一个 LookUpEdit 来拥有两个值成员? 它是独立使用还是在网格中使用? 如果是独立的,您可以根据当前行交换两个存储库编辑器。 但是,ValueMember 是否有超过 2 个可能的值? 这也会让事情变得复杂。

更新

看着你的编辑,我想我更了解发生了什么。 那么,您不想更改 ValueMember (指数据列),而是更改编辑器的值? 如果是这样,那么您绝对应该使用 EditValue (不是 SelectedText,我不认为它是要设置的),并将其分配给 row["value_field"] ,如下所示:

lkuResidenceCounty.EditValue = row["ResidencyCountyID"];

当您这样做时会发生什么?

Why is it that you need the same LookUpEdit to have two value members? Is it being used standalone or in a grid? If standalone, you could swap out the two repository editors depending on the current row. But, are there more than 2 possible values for the ValueMember? That would also complicate things.

UPDATE

Looking at your edit, I think I understand what's going on a little more. So, you don't wish to change your ValueMember (which refers to a data column), but rather to change the value of the editor? If so, then you should definitely use EditValue (not SelectedText, which I don't believe is meant to be set), and assign it to row["value_field"] like so:

lkuResidenceCounty.EditValue = row["ResidencyCountyID"];

What happens when you do that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文