首页 \ 问答 \ 通过列表框的索引强制选择或取消相同的值(Force selection by index of listbox or take apart same values)

通过列表框的索引强制选择或取消相同的值(Force selection by index of listbox or take apart same values)

我使用文本框和按钮将项目添加到列表框:

if (tbName.Text != "")
{
     listBox.Items.Add(tbName.Text);
     //Let user add another new items
     tbName.Text = "";
}

并尝试选择执行某些操作的项目(因为我编辑它)。

但问题是用户可以添加相同的项目值,而当我尝试选择其中一个项目时,会导致失败。 它会自动选择两个相同名称的项目,操作不正确。

在此处输入图像描述

我可以使用某种方法强制列表框按索引选择项目(因为索引不应该相同)? 或者我如何通过编程分割相同的项目值(它不会选择相同的项目,只是选择我点击的内容,这是否意味着我应该通过选择项目拦截MouseDown或SelectChanged的事件参考鼠标点击的位置,像线的高度是18px,所以如果我点击的位置在18~36px之间,那么选择项的索引应该是1,0是0~18px)?

我的listBox是:

<ListBox Height="248" HorizontalAlignment="Left" Margin="141,223,0,0" Name="listBox" VerticalAlignment="Top" Width="378" />

I use textbox and button to add items to listbox:

if (tbName.Text != "")
{
     listBox.Items.Add(tbName.Text);
     //Let user add another new items
     tbName.Text = "";
}

And try to select items doing something (as I edit it).

But the trouble is the user can add same value of item, and while I try to select one of the item, it will result in failure. It will auto-select two items by same name, and the operation will be improper.

enter image description here

Can I use some method to force the listbox select items by index( since the index shouldn't be same)? Or how can I take apart the same value of items by programming(it won't select same item but just select what I click, is it means I should intercept the event of MouseDown or SelectChanged by select items refer to the position of mouse click, like height of the line is 18px, so if the position I click is between 18~36px, then the index of select item should be 1, and 0 is 0~18px)?

My listBox is:

<ListBox Height="248" HorizontalAlignment="Left" Margin="141,223,0,0" Name="listBox" VerticalAlignment="Top" Width="378" />

原文:https://stackoverflow.com/questions/19680996
更新时间:2021-12-14 07:12

最满意答案

根据我的理解,实现这一目标的唯一方法是事先创建一个配置文件,并在nightwatch配置中使用该配置文件,类似于这里的文章: https//github.com/nightwatchjs/nightwatch/wiki/Enable-Firebug-in-火狐换Nightwatch检验

我希望有一种方法来设置firefox首选项,因为我提供的解决方案依赖于在配置文件的机器上运行。


From my understanding the only way to accomplish this is to create a profile before hand and use that profile in nightwatch configuration, similar to the insructions here: https://github.com/nightwatchjs/nightwatch/wiki/Enable-Firebug-in-Firefox-for-Nightwatch-tests

I wish there was a way to set firefox preferences, since with the solution I'm providing your tests are dependent on running on the machine with the profile.

相关问答

更多
  • 好吧,现在它可以工作。 如果您遇到相同或类似的问题,请编辑harness-options.json文件。 后 "page-mod": { "path": "addon-kit/lib/page-mod.js" }, 加: "preferences-service": { "path": "api-utils/lib/preferences-service.js" }, /*with or without the comma, as the case may */ 就这样 :) Okay, now it ...
  • 解决方案是为您的守夜测试创建一个Firefox配置文件。 1)创建一个新的Firefox配置文件: 在终端中,执行以下命令:“ firefox -p ” 然后创建一个名为“ webdriver ”的profil 。 2)配置新的配置文件 使用url: about:config转到此配置页面 搜索名称“ intl.accept_languages ”并更新值。 现在退出Firefox。 3)配置Nightwatch以使用新的配置文件 “webdriver.firefox.profile”:“ webdrive ...
  • 看起来您需要在.xul文件中包含nsUserSettings.js :