如何防止带有复选框的 AC# Listview 控件“检查”关于行选择?

发布于 2024-11-14 07:13:01 字数 1448 浏览 8 评论 0原文

环境

  • Windows XP x32 Visual Studio 2005 标准版
  • Honeywell Dolphin 9500 运行 Windows Mobile 2003 (Pocket PC 2003) 具有内置条码扫描仪和黑白相机 使用位于 此处
  • .NET Compact Framework 1.0 SP3 和 .NET Framework 1.1
  • 使用 VC#

目标

我在表单上有一个带有 CheckBoxes = trueView = Details 的 ListView 控件,但我没有希望用户可以“选中”复选框。我用它来显示记录完成的状态。不过,我确实想使用事件处理函数通过代码选中该框(即记录完成时:lvMeters_ItemCheck(null, null);)。

问题

我已经禁用了选中该框本身(我认为,该设备上的触摸屏并不真正精确)。但是,当选择一行(我有 FullRowSelect = true)时,控件经常检查复选框,并且事件处理程序似乎没有被调用。

我尝试过的事情

我尝试基本上撤消事件处理程序中的操作:

private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (sender is ListView)
    {
        if (e.CurrentValue == CheckState.Checked)
            lvMeters.Items[e.Index].Checked = true;
        else
            lvMeters.Items[e.Index].Checked = false;
    }
    else if (e.CurrentValue == CheckState.Checked)
        lvMeters.Items[e.Index].Checked = false;
    else
        lvMeters.Items[e.Index].Checked = true;
}

问题是上面的处理程序不会在列表视图选择上被调用,SelectedItemChanged事件处理程序也不会调用此事件处理程序,但它仍然选中选择上的框。当选中该框本身时,它确实会被调用。

需要更多信息吗?

询问吧,我会尽力而为!

我是新手

,所以请随时告诉我我这样做完全错误,应该以不同的方式做整个事情。

Environment

  • Windows XP x32 Visual Studio 2005 Standard Edition
  • Honeywell Dolphin 9500 running Windows Mobile 2003 (Pocket PC 2003) With built in Barcode scanner and B&W camera Using their SDK located here.
  • .NET Compact Framework 1.0 SP3 and .NET Framework 1.1
  • Using VC#

Goal

I have a ListView control with CheckBoxes = true and View = Details on a form but I don't want the check boxes to be "checkable" by the user. I am using it for a status display of record completion. I do, however, want to use the event handler function to check the box via code (i.e. on record completion: lvMeters_ItemCheck(null, null);).

Problem

I have disabled checking the box itself (I think, the touch screen isn't real precise on this device). However, when selecting a row (I have FullRowSelect = true), the control often checks the checkbox and the event handler doesn't seem to be getting called.

Things I have Tried

I tried to basically undo the action in the event handler:

private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (sender is ListView)
    {
        if (e.CurrentValue == CheckState.Checked)
            lvMeters.Items[e.Index].Checked = true;
        else
            lvMeters.Items[e.Index].Checked = false;
    }
    else if (e.CurrentValue == CheckState.Checked)
        lvMeters.Items[e.Index].Checked = false;
    else
        lvMeters.Items[e.Index].Checked = true;
}

The problem is the above handler doesn't get called on a listview select, nor does the SelectedItemChanged event handler call this event handler but it's still checking the box on select. It does get called when checking the box itself.

Need additional information?

Ask away and I'll do my best!

I'm A Novice

So please feel free to tell me I am doing this completely wrong and should do the entire thing differently.

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

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

发布评论

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

评论(2

迷迭香的记忆 2024-11-21 07:13:01

我不熟悉ListView在紧凑框架上的限制,但是在标准框架上,您可以使用 TreeNode.StateImageIndex 属性。未检查/检查状态实际上是使用标准 winforms 代码中嵌入的小图像(如果我没记错的话,它们是索引 1 和 2)。因此,例如,如果您这样做:

private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
    e.Item.StateImageIndex = 3;
}

它将更改小图标并将其设置为空。您还可以使用 ListView ImageList。

I'm not familiar with the limits of the ListView on the compact framework, but on the standard framework, you can use the TreeNode.StateImageIndex property. The unchecked/checked states are in fact using small images embedded in the standard winforms code (If I remember correctly, they are index 1 and 2). So, for example, if you do this:

private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
    e.Item.StateImageIndex = 3;
}

It will change the small icon and set it to nothing. You can also use the ListView ImageList.

蘸点软妹酱 2024-11-21 07:13:01

叹息...我在与设计器混淆时设法从控件中删除了事件处理程序。我在某个时候检查过,它仍然在那里,但那时我实际上确实遇到了逻辑/代码问题。

感谢您的回答:/

Sigh...I somehow managed to remove the event handler from the control when muddling with the designer. I checked at some point and it was still there but at that point I actually did have a logic/code problem.

Thanks for your answers :/

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