The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Listview Checked event...
Posted: 08 Aug 06 9:53 AM
|
fiogf49gjkf0d Hi,
I am using a listview with check boxes. There doesn't seem to be an event that captures when the user checks/unchecks the box. I tried putting code on the OnSelectItem event but that didn't fire when I checked the checkbox.
Anyone have any ideas on going about how to do this?
Thanks. Terry
|
|
|
|
Re: Listview Checked event...
Posted: 08 Aug 06 12:15 PM
|
fiogf49gjkf0d Public Function GetCheckedItems 'Function ' Returns an Array of Strings of checked items in a ListView
'Syntax ' GetCheckedItems
'Parameters ' None
' Returns ' Array of Strings dim integerIndex, integerItemsCount, integerUBound dim stringResult On Error Resume Next stringResult = "" if (not (m_listview is nothing)) then redim stringResult(0) with m_listview integerItemsCount = .Items.Count - 1 for integerIndex = 0 to integerItemsCount if (.Items.Items(integerIndex).Checked) then if (stringResult(0) = "") then stringResult(0) = .Items.Items(integerIndex).Caption else integerUBound = UBound(stringResult) + 1 redim preserve stringResult(integerUBound) stringResult(integerUBound) = .Items.Items(integerIndex).Caption end if end if next end with if (stringResult(0) = "") then stringResult = "" end if end if GetCheckedItems = stringResult ErrorCheck(Application.Translator.Localize("SFCListView.GetCheckedItems:")) On Error Goto 0 End Function
OnSelectItem doesn't fire because technically the row isn't selected. OnClick or OnMouseDown may be the only event you have that will do what you're suggesting.
Instead of processing on each check, I do processing on the AXFormValidate event of the form my listview is on. The GetCheckedItems method lets me store the array of primary key values in a memo field which I then serialize back into checked items when the form is reopened.
In 6.1 I used a listview in this configuration to mimic a multi-select datagrid. 6.2 datagrids are multi-select so you may have a better time using a datagrid instead of a listview. There may be a way to hack something together using my method above but it'd be difficult to narrow it down to just one selected value. |
|
|
|
Re: Listview Checked event...
Posted: 08 Aug 06 12:47 PM
|
fiogf49gjkf0d Thanks Jeremy!
I was going to have an item that would read "Check All" and have that followed by a list of items. So, when the Check All box was checked, it would check, well, all of them for the user. If it was unchecked it would uncheck everything.
I didn't see the OnClick or OnMouseDown events on the Event tab that appears on the Properties Page. So I assumed they weren't available. I tried creating my own event and that didn't work.
I might have to take the Check All option off. No biggie.
Thanks again. Terry
|
|
|
|
Re: Listview Checked event...
Posted: 08 Aug 06 2:08 PM
|
fiogf49gjkf0d Here's the SelectAllItems method I use:
Public Sub SelectAllItems 'Sub ' Checks all of the checkboxes of a ListView with Checkboxes = true
'Syntax ' SelectAllItems
'Parameters ' None dim integerIndex, integerItemsCount On Error Resume Next if (not (m_listview is nothing)) then with m_listview integerItemsCount = .Items.Count - 1 for integerIndex = 0 to integerItemsCount .Items.Items(integerIndex).Checked = true next end with end if ErrorCheck(Application.Translator.Localize("SFCListView.SelectAllItems:")) On Error Goto 0 End Sub
m_listview in both methods is the listview object itself (set m_listview = ListView1).
You could use a popupmenu that would be triggered on the OnMouseDown event of the ListView (and only when the right mouse button is pressed). Store a boolean that determines when select all has been triggered. This way you can use the same popupmenu item to trigger both a select and deselect instead of using 2 menu items. |
|
|
|