How can I save a C # list control using the check boxes on the 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 its 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 the form, but I don’t want the checkboxes to be “checked” by the user. I use it to display the recording completion status. However, I want to use the event handler function to check the field through the code (i.e., End recording: lvMeters_ItemCheck(null, null); ).

Problem

I turned off checking the window itself (I think the touch screen is not accurate on this device). However, when selecting a row (I have FullRowSelect = true ), the control often checks the checkbox, and the event handler does not seem to be called.

Things i tried

I tried basically to 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 that the above handler is not called when the list is selected, and the SelectedItemChanged event handler does not call this event handler, but it still checks the checkbox when it is selected. It is called when checking the window itself.

Need more info?

Ask and I will do my best!

I'm new at this

Therefore, please do not hesitate to tell me that I am doing this completely wrong and should do everything differently.

+6
source share
2 answers

Sigh ... I somehow managed to remove the event handler from the control when I got confused with the designer. I checked at some point and it was still there, but at that moment I really had a problem with logic / code.

Thank you for your responses:/

0
source

I am not familiar with the limitations of ListView on a compact structure, but in the standard structure you can use the TreeNode.StateImageIndex property. Uncontrolled / checked states actually use small images embedded in the standard winforms code (if I remember correctly, these are indices 1 and 2). So, for example, if you do this:

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

He will change the small icon and will not change anything. You can also use ListView ImageList.

0
source

Source: https://habr.com/ru/post/889902/


All Articles