PDA

View Full Version : How to access a Checkbox in a ListView per row?



lionne
04-11-2013, 05:14 AM
Dear all,

I couldn't find information on the following: is it possible to access a CheckBox in a ListView individually?

I've got a ListView with CheckBoxes. The ListItem can be .Selected or .Checked, which will execute different routine. I've got some conditions, if the row (item) is allowed to be checked or not. That means I'd like to either:

- be able to show/hide the checkbox per row.
AFAIK checkboxes can be enabled/disabled for the entire ListRow via


.CheckBoxes = True


or

- be able to enable/disable the checkbox per row.

Is it possible at all? Any help would be highly appreciated.

Aflatoon
04-11-2013, 05:27 AM
You cannot as far as I know only have the checkboxes visible on certain rows if that is what you are asking?

lionne
04-11-2013, 05:43 AM
Yes, that would be great too!!!

Aflatoon
04-11-2013, 06:10 AM
I said you cannot do that.

lionne
04-11-2013, 06:29 AM
:aw

Anyway, thanks for looking at the problem.

Another solution here might be by disabling/hiding the value of an item per row. Is that possible?

Aflatoon
04-11-2013, 08:30 AM
Can you give an example? (A sample file would help)

lionne
04-11-2013, 08:31 AM
Thanks to Passel

http://www.xtremevbtalk.com/showthread.php?t=193514&highlight=listview

I could adapt his trick with a tag property, so that a user is not able to check the checkbox:



Private Sub UserForm_Activate()
Dim li As ListItem
With Export.lsv_tcList
If ... Then
li.Tag = "V"
End if
End with
End Sub


Private Sub lsv_tcList_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Tag = "V" Then
Item.Checked = False
End If
End Sub


However, the user will not know, which boxes are checkable, which is not nice.

Any suggestions?

SamT
04-11-2013, 10:08 AM
I can't see all your code, but try

If Item.Tag = "V" Then
Item.Enabled = False

And see what happens.

lionne
04-12-2013, 03:29 AM
Thanks, but unfortunately there's no such property.

snb
04-12-2013, 03:43 AM
Why do you populate a control containing items a user isn't allowed to select ?

You can populate any control with a filtered list of valid choices.

lionne
04-12-2013, 03:53 AM
Well, because the data my ListView is populated with is variable. I then extract this data to an .xml file. If one condition is fulfilled, then some rows are not allowed to be extracted.

Unfortunately, the ListView can be with or without checkboxes, which means, I can only disable it to not let a user set its value to True. I was able to do it, but user has to somehow differentiate, which data can be extracted, and which not. In order to achieve that, I'd like either to:

- highlight the row or
- outgrey the checkbox.

But it seems to me, that neither of these is possible...

lionne
04-12-2013, 03:58 AM
http://i47.tinypic.com/25ywwav.png

my UserForm looks like this. Some rows here are to be exported, so I do: if .Selected = True Then Export etc.

Other rows are to be exported with CheckBox checked (in this case, one additional tag is added into .xml file). So I do: If .Selected = True and .Checked = True etc.

Others are not allowed to be exported with CheckBox checked.

The ones, that are not allowed to be exported at all are not shown.
http://postimg.org/image/55750de9n/

JKwan
04-12-2013, 06:32 AM
You can individually color the cell that make up the row that you don't want users to export (along that line)


ListView.ListSubItems.Item(n).ForeColor = vbRed

So, now you check the fore ground color, if red, cannot export.
Sounds like it may work??

lionne
04-12-2013, 06:48 AM
Thanks JKwan for looking at my problem!

You're right, it works like that, but .ForeColor colors up the font, not the cell. Something like .BackColor would be nicer here. Plus, there's no way to highlight the cell with a checkbox, I guess... I didn't find one.

Meanwhile that's the only solution. Let's see, if the customer is satisfied with that...

JKwan
04-12-2013, 08:08 AM
Will this work, uses APIs
http://vbnet.mvps.org/index.html?code/comctl/lvledger.htm

SamT
04-12-2013, 08:31 AM
No Item = Can't select

Private Sub lsv_tcList_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Tag = "V" Then
Item.Remove
End If
End Sub