我ListView在WPF中有一个简单的实现,它允许我通过按住鼠标按钮并拖动项目来选择列表中的多个项目.但是,在按住鼠标按钮的同时,当我将鼠标移到外面ListView时,选择会发生奇怪的事情.理想情况下,我只希望选择保持不变,而是快速遍历所有选定的项目,只留下选择的最后一项.
这是代码,有什么想法吗?
public class MultiSelectListView : ListView
{
private bool m_isSelectionActive;
public bool IsSelectionActive
{
get { return m_isSelectionActive; }
}
protected override DependencyObject GetContainerForItemOverride()
{
return new MultiSelectListViewItem(this);
}
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
m_isSelectionActive = true;
}
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
m_isSelectionActive = false;
}
}
public class MultiSelectListViewItem : ListViewItem
{
private readonly MultiSelectListView m_parent;
public MultiSelectListViewItem(MultiSelectListView parent)
{
m_parent = parent;
}
protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
{
if …Run Code Online (Sandbox Code Playgroud) 我在我的智慧的尽头试图弄清楚这一点。我在 WPF 方面很有经验,但我从未见过这样的事情。
我有一个包含可选 ListBoxItems 的 ListBox。列表中的项目可以通过鼠标点击或使用向上/向下箭头来选择。我正在使用 SelectionMode.Extended,所以我的列表支持多选。
问题:单击列表中的一个项目,然后按住 Shift 的同时单击另一个项目,会像您期望的那样选择正确的项目范围。不幸的是,使用向上/向下箭头无法正常工作 - 相反,选择的范围似乎总是基于最后一个 CLICKED 项目,而不是使用箭头键选择的项目。
例如:
[Item 1] <- Click this item
[Item 2] <- Use the down arrow to select this item
[Item 3] <- Shift-Click this item
Run Code Online (Sandbox Code Playgroud)
您可能希望选择项目 2 和 3,而是选择所有项目(1、2 和 3)。
所有 ListBox 属性都有正确的值(即使用箭头键更新 SelectedItems 属性),我唯一的问题似乎是 ListBox 如何在内部处理 Shift-Click 选择。据我所知,我相信这与 ListBox 的“多选锚点”通过鼠标点击设置有关,但与箭头键无关。
有没有人遇到并解决过这个问题?有没有办法手动设置“多选锚点”?谢谢你的帮助!
克里斯
我有一个选择倍数的表单.我想在onchange事件中获取所有选定的值,但我不知道这是否可行.我认为"this.value"只返回选中的最后一个元素.
是否有可能在onchange上将所有元素选为数组?
提前致谢.
<select name="myarray[]" id="myarray" class="select2-select req" style="width: 90%;" onChange="get_values(this.value)" multiple>
{foreach key=key item=value from=$myarray}
<option value="{$key}" >{$value}</option>
{/foreach}
</select>
Run Code Online (Sandbox Code Playgroud) 这是我经常遇到的问题.让我通过一个简化的例子解释一下:
假设我想显示一个搜索页面,其中可以通过选择一个或多个产品类别来过滤结果.在视图中,这看起来像:
<%= select_tag("product_categories", options_from_collection_for_select(@product_categories, 'id', 'name'), multiple:true, include_blank:"(all categories)" %>
Run Code Online (Sandbox Code Playgroud)
现在,在控制器中,我有类似的东西:
@filtered_products = Product.all
...
if params[:product_categories].present?
@filtered_products = @filtered_products.where(category_id: params[:product_categories].map(&:to_i))
end
...
#etc
Run Code Online (Sandbox Code Playgroud)
但是,由于单击时无法取消选择多选,因此有一个空白选项.但是,当设置此选项时,params[:product_categories]包含[""].这导致if语句被评估,并且作为".to_i == 0,我们只获得类别为0的产品(通常为none,因为ActiveRecord在数据库中从1开始id).这不是理想的结果,因为实际上我们想要选择空白选项时的所有产品.
处理这种情况变得更加困难,因为可能意外地选择空白选项和一个或多个其他选项.所以这种情况也需要处理.
我已将if语句更改为
if params[:product_categories].present? && params[:product_categories].any? && (params[:product_categories].length > 1 || params[:product_categories].first != "")
...
end
Run Code Online (Sandbox Code Playgroud)
它有效,但这段代码非常难看.我想知道是否有更好,更干,更Rails的方式来做到这一点.
我需要捕捉这两个事件:
Reason is - that I want to disable another dropdown (which is responsible for the content of my multiselect) when the first option is selected or all previous selected are deselected.
更新:
$('.projectSelector').on('change', function() {
var targetProject_id = $('#project-id :selected').val();
updateParticpantDropdown(targetProject_id);
});
function updateParticpantDropdown(selectedProjectId){
$.ajax({
type: "POST",
url: '/xx/projects/xx/'+ selectedProjectId,
dataType : "json",
success: function (response, status) {
if(status === "success") {
//console.log('success post');
if(response.result == "error") {
alert(response.message);
}else if (response.result == "success"){
var data = …Run Code Online (Sandbox Code Playgroud) 我正在为 React 使用 Ant 设计组件。我想固定多选输入字段的大小,以便将所选值放入同一行而不采用新行,就像默认行为:
https://ant.design/components/select/#components-select-demo-multiple
我需要将值放在同一行中。
我可以通过覆盖样式来固定输入字段的大小
.ant-select-selection--multiple:before, .ant-select-selection--multiple:after {
display: inline !important; }
Run Code Online (Sandbox Code Playgroud)
但是当我选择几个值时,它们就在 inputr 字段之外。
我正在使用bootstrap-multiselect为用户提供两个关键菜单上的出色控制器。我的第一个菜单被称为groups和其他被称为queues. 队列中的每个选项都有一个 HTML5 数据属性(即 data-group="X",其中 X 是组值)
当用户从groups菜单中选择一个选项/组时,我想查找并隐藏queues菜单中data-group不等于组菜单中选定组的每个队列/选项。
在确定需要隐藏/显示的队列/项目后,我尝试使用.show()和.hide()扩展。然后我尝试使用.addClass('hidden')和.removeClass('hidden')方法,但没有什么对我有用。
如何使用bootstrap-multiselect 动态显示/隐藏项目?
这是我的代码
$(function () {
var queueGroupIds = $('#QueueGroupIds');
var queueIds = $('#QueueIds');
queueGroupIds.multiselect({
nonSelectedText: 'Select group(s)',
onChange: function (option, checked, select) {
var groups = queueGroupIds.find('option:selected');
if (groups.length == 0) {
//When none of the groups are selected, show all queues!
queueIds.find('option').each(function (i, q) {
$(q).show();
}); …Run Code Online (Sandbox Code Playgroud) javascript jquery multi-select twitter-bootstrap bootstrap-multiselect
我在单选模式下使用 vue-multiselect 并尝试应用样式使选项下拉列表与最宽选项的宽度相同。我实现了这一点,但无法让 .multiselect__option 与父 .multiselect__element 的宽度相同:
https://jsfiddle.net/xo9f7jby/30/
.multiselect {
width: fit-content
}
.multiselect__content-wrapper, .multiselect__element {
width: fit-content;
}
.multiselect__option {
width: 100%;
}
Run Code Online (Sandbox Code Playgroud) 我正在做一个有列表的 Ionic 项目。我想要一个多选功能,就像 android 库中的保持和选择功能一样,这样长按复选框就会出现在列表项的前面,使我能够选择多个项目。
关于如何实施的任何建议?我不是在寻找 GalleryView功能,而只是长按并选择功能,就像它一样。
是否可以不创建实际的复选框?或者我是否需要创建复选框并实施暂停事件?
注意:对于我是否要实现android画廊功能感到困惑的人,请注意!我不想在这里实现 android 画廊功能。我只想在简单列表上实现一个多选功能,就像我们在android画廊中长按选择多个图像一样,甚至以在联系人列表中选择多个联系人为例,等等。
我有两个类,称为User和Role。
class User
{
...
public List<Role> Roles;
}
class Role
{
...
public int ID;
public string Name;
}
Run Code Online (Sandbox Code Playgroud)
我也有一个动作(提交)
public IActionResult Submit(User user)
{
...
}
Run Code Online (Sandbox Code Playgroud)
在我的 Index.cshtmlselect是
<select multiple="multiple" class="multi-select" id="my_multi_select1" asp-for="Roles" asp-items="ViewBag.Roles"></select>
Run Code Online (Sandbox Code Playgroud)
和ViewBag.Roles价值是
ViewBag.Roles= new SelectList(Role.SelectAll(), "Name", "Name");
Run Code Online (Sandbox Code Playgroud)
问题是,当我发表我的表单,数据这样的发送
...&Roles=role1,role2&...
等user.Roles成为空,而我希望有两个角色与名字role1,并role2和它们分配到user.Roles(实际上,我希望ASP这是否)