-
Nov 24th, 2020, 04:22 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Enable/disable entries in listview controls
I have two ListView controls with checkboxes enabled. Both ListViews have the same entries. The one ListView is for entries that must be included and the second ListView is for entries that must be excluded.
How can I disable/enable an entry in one ListView when the equivalent entry in the other ListView is selected/deselected?
Say, for instance, both ListViews contain the words Red, Blue, Green, Black.
When the user select the checkbox next to Red in the first ListView the entry for Red in the second ListView must be disabled so that Red can't be selected in the second ListView. And when the checkbox next to red is deselected in the first ListView then the Red entry in the second ListView must be enabled again so that it is available for selection again if needed.
Is this possible?
PS. It must work both ways.
-
Nov 24th, 2020, 09:42 PM
#2
Re: Enable/disable entries in listview controls
Are you using the 'Microsoft Windows Common Controls 5.0' or 'Microsoft Windows Common Controls 6.0'?
If you're using 6.0 it has a built-in event for when an item is checked, so it's very easy to set:
Code:
Private Sub ListView2_ItemCheck(ByVal Item As LvwListItem, ByVal Checked As Boolean)
If (Item.Index = [indexofRed]) And (ListView1.ListItems([indexofRed]).Checked = True) Then
If Checked = True Then
Item.Checked = False
End If
End If
End Sub
You'd put the same kind of thing in the event for ListView1_ItemCheck to make it work both ways.
Last edited by fafalone; Nov 24th, 2020 at 09:45 PM.
-
Nov 25th, 2020, 02:44 AM
#3
Thread Starter
Hyperactive Member
Re: Enable/disable entries in listview controls
Thanks. I was thinking of disabling the listitem in the other listview but just unselecting it there also works. Always over complicating things
Just one question. Is there a way to hide the ugly blue selection of the list items?
When user select/deselect the checkboxes in the listview the first item gets highlighted and stays highlighted as other checkboxes in the listview are selected/deselected. Or when user clicks on the list items the selected list item gets highlighted and stays highlighted until another item are clicked, which are then highlighted, or the listview loses focus.
-
Nov 25th, 2020, 05:09 AM
#4
Thread Starter
Hyperactive Member
Re: Enable/disable entries in listview controls
Thanks for pointing me in the right direction.
Got it working. At least the ugly highlight jumps around with the selections as they are made
Code:
Private Sub lvwInclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
lvwInclude.ListItems(Item.Index).Selected = True
If lvwInclude.ListItems(Item.Index).Checked = True Then
lvwExclude.ListItems(Item.Index).Checked = False
lvwExclude.ListItems(Item.Index).Selected = True
End If
End Sub
Private Sub lvwInclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
lvwInclude.ListItems(Item.Index).Checked = Not lvwInclude.ListItems(Item.Index).Checked
lvwInclude_ItemCheck Item
End Sub
Private Sub lvwExclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
lvwExclude.ListItems(Item.Index).Checked = Not lvwExclude.ListItems(Item.Index).Checked
lvwExclude_ItemCheck Item
End Sub
Private Sub lvwExclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
lvwExclude.ListItems(Item.Index).Selected = True
If lvwExclude.ListItems(Item.Index).Checked = True Then
lvwInclude.ListItems(Item.Index).Checked = False
lvwExclude.ListItems(Item.Index).Selected = True
End If
End Sub
-
Apr 25th, 2023, 08:00 AM
#5
Lively Member
Re: Enable/disable entries in listview controls
Friends,
I am having a listview and I have loaded all the DB values.
First Column is Check Box.
If i checked, the calculation will be made and values will be stored in DB including the checked value too.
In next time loading, the checked row is showing as checked. But I don't want to deselect and the specific row need to be disabled (protect from unselect)
How can i do that? please guide me.
Thanks.
Originally Posted by Bezzie
Thanks for pointing me in the right direction.
Got it working. At least the ugly highlight jumps around with the selections as they are made
Code:
Private Sub lvwInclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
lvwInclude.ListItems(Item.Index).Selected = True
If lvwInclude.ListItems(Item.Index).Checked = True Then
lvwExclude.ListItems(Item.Index).Checked = False
lvwExclude.ListItems(Item.Index).Selected = True
End If
End Sub
Private Sub lvwInclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
lvwInclude.ListItems(Item.Index).Checked = Not lvwInclude.ListItems(Item.Index).Checked
lvwInclude_ItemCheck Item
End Sub
Private Sub lvwExclude_ItemClick(ByVal Item As MSComctlLib.ListItem)
lvwExclude.ListItems(Item.Index).Checked = Not lvwExclude.ListItems(Item.Index).Checked
lvwExclude_ItemCheck Item
End Sub
Private Sub lvwExclude_ItemCheck(ByVal Item As MSComctlLib.ListItem)
lvwExclude.ListItems(Item.Index).Selected = True
If lvwExclude.ListItems(Item.Index).Checked = True Then
lvwInclude.ListItems(Item.Index).Checked = False
lvwExclude.ListItems(Item.Index).Selected = True
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|