How Can I Keep A C# Listview Control with Check Boxes from "Checking" on Row Selection?
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.
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.
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 :/
精彩评论