gpt4 book ai didi

c# - 多选 ListView 中的 ListView 选定索引已更改

转载 作者:太空宇宙 更新时间:2023-11-03 16:54:00 24 4
gpt4 key购买 nike

我有一个带有 ListView 控件的窗口窗体。我将 MultiSelect 属性设置为 true 并添加了 selected_index changed 事件。

当我点击与当前选定索引相同的索引时,事件被触发。我的期望是我不会触发该事件。奇怪的是,在我单击索引后 1 秒事件触发。

感谢任何解释为什么会发生这种情况的回复。

编辑:

示例代码:

private void Form1_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.MultiSelect = true;
listView1.FullRowSelect = true;

listView1.Columns.Add("Number");
listView1.Items.Add("1");
listView1.Items.Add("2");
listView1.Items.Add("3");
listView1.Items.Add("4");
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
MessageBox.Show("Selected Index Changed event fired: ");
}
}

按照以下步骤查看问题:

  1. 尝试选择一项,例如:选择数字3

    预期结果:listview1_SelectedIndexChanged 被触发

    结果:它被解雇了。

  2. 尝试再次点击数字 3。

    预期结果:listview1_SelectedIndexChanged 未触发

    结果:延迟一秒触发。

最佳答案

来自 ListView.SelectedIndexChangedEvent 的 MSDN 文档:

In a multiple selection ListView control, this event occurs whenever an item is removed or added to the list of selected items. To determine which items are selected in the ListView control, use the SelectedItems property to access the ListView.SelectedListViewItemCollection.

至于为什么事件要等这么久才触发:我只能想象处理器忙于做其他事情。关于您所看到的内容,您是否有更多详细信息(示例代码会有所帮助)?

关于c# - 多选 ListView 中的 ListView 选定索引已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2885840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com