Newsgroup: it.comp.lang.visual-basic
Titolo: problema con Trevieew

perché questo codice non funziona?
Private Sub tv_NodeCheck(ByVal Node As MSComctlLib.Node)
Set Nod = Node
   If Nod.Text <> "Pippo" Then
       tv.Nodes(Nod.Index).Checked = False
   End If
End Sub
Voglio che solo i nodi con pippo vengano ceccati e gli atri no.
Esegue il codice ma nella Treview non succede nulla.
Ciao
-- 
Posted via Mailgate.ORG Server - 
http://www.Mailgate.ORG

    End If
o meglio:
tv.nodes(nod.index).cheched = (lcase(not.text) = "pippo")


 wrote in message
news:0zwX9.88775$
AA2.3...@news2.tin.it

No.
Dovrebbe essere un Bug.
Ho risolto comunque utilizzando le api.
Posto l'esempio in modo che possa essere utile a qualcuno.
Dichiarazioni nel Modulo:
Option Explicit
Public Enum TVItemCheckStates
  tvisNoCheckboxes = 0
 
  tvisUncheckedB = 1
  tvisCheckedB = 2
  tvisUnchecked = 3
  tvisChecked = 4
 
  tvisUnXedB = 5
  tvisXedB = 6
  tvisUnXed = 7
  tvisXed = 8
 
  tvisUnBullseyedB = 9
  tvisBullseyedB = 10
  tvisUnBullseyed = 11
  tvisBullseyed = 12
End Enum   ' TVItemCheckStates
Public Enum TVItemStates
  TVIS_SELECTED = &H2
  TVIS_CUT = &H4
  TVIS_DROPHILITED = &H8
  TVIS_BOLD = &H10
  TVIS_EXPANDED = &H20
  TVIS_EXPANDEDONCE = &H40
#If (WIN32_IE >= &H300) Then
  TVIS_EXPANDPARTIAL = &H80
#End If
 
  TVIS_OVERLAYMASK = &HF00
  TVIS_STATEIMAGEMASK = &HF000
  TVIS_USERMASK = &HF000
End Enum
Public Type TVITEM   ' was TV_ITEM
  mask As TVItemMasks
  hItem As Long
  state As TVItemStates
  stateMask As Long
  pszText As String   ' Long   ' pointer
  cchTextMax As Long
  iImage As Long
  iSelectedImage As Long
  cChildren As Long
  lParam As Long
End Type
Public Enum TVItemMasks
  TVIF_TEXT = &H1
  TVIF_IMAGE = &H2
  TVIF_PARAM = &H4
  TVIF_STATE = &H8
  TVIF_HANDLE = &H10
  TVIF_SELECTEDIMAGE = &H20
  TVIF_CHILDREN = &H40
#If (WIN32_IE >= &H400) Then   ' WIN32_IE = 1024 (>= Comctl32.dll v4.71)
  TVIF_INTEGRAL = &H80
#End If
  TVIF_DI_SETITEM = &H1000   ' Notification
End Enum
Public Enum TVM_GETNEXTITEM_wParam
  TVGN_ROOT = &H0
  TVGN_NEXT = &H1
  TVGN_PREVIOUS = &H2
  TVGN_PARENT = &H3
  TVGN_CHILD = &H4
  TVGN_FIRSTVISIBLE = &H5
  TVGN_NEXTVISIBLE = &H6
  TVGN_PREVIOUSVISIBLE = &H7
  TVGN_DROPHILITE = &H8
  TVGN_CARET = &H9
#If (WIN32_IE >= &H400) Then
  TVGN_LASTVISIBLE = &HA
#End If
End Enum
Public Const TV_FIRST = &H1100
Public Const TVM_GETNEXTITEM = (TV_FIRST + 10)
Public Const TVM_SETITEM = (TV_FIRST + 13)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                            (ByVal hWnd As Long, _
                            ByVal wMsg As Long, _
                            wParam As Any, _
                            lParam As Any) As Long   ' <---
Public Function SetTVItemStateImage(hwndTV As Long, _
                                                              hItem As
Long, _
                                                              iState As
TVItemCheckStates) As Boolean
  Dim tvi As TVITEM
 
  tvi.mask = TVIF_HANDLE Or TVIF_STATE
  tvi.hItem = hItem
  tvi.stateMask = TVIS_STATEIMAGEMASK
  tvi.state = INDEXTOSTATEIMAGEMASK(iState)
 
  SetTVItemStateImage = TreeView_SetItem(hwndTV, tvi)
 
End Function
Public Function TreeView_SetItem(hWnd As Long, pitem As TVITEM) As
Boolean
  TreeView_SetItem = SendMessage(hWnd, TVM_SETITEM, 0, pitem)
End Function
Public Function TreeView_GetItem(hWnd As Long, pitem As TVITEM) As
Boolean
  TreeView_GetItem = SendMessage(hWnd, TVM_GETITEM, 0, pitem)
End Function
Public Function INDEXTOSTATEIMAGEMASK(iIndex As Long) As Long
' #define INDEXTOSTATEIMAGEMASK(i) ((i) << 12)
  INDEXTOSTATEIMAGEMASK = iIndex * (2 ^ 12)
End Function
Public Function TreeView_SetImageList(hWnd As Long, himl As Long, iImage
As Long) As Long
  TreeView_SetImageList = SendMessage(hWnd, TVM_SETIMAGELIST, ByVal
iImage, ByVal himl)
End Function
Public Function TreeView_GetSelection(hWnd As Long) As Long
  TreeView_GetSelection = TreeView_GetNextItem(hWnd, 0, TVGN_CARET)
End Function
Public Function TreeView_GetNextItem(hWnd As Long, hItem As Long, flag
As Long) As Long
  TreeView_GetNextItem = SendMessage(hWnd, TVM_GETNEXTITEM, ByVal flag,
ByVal hItem)
End Function
'---------------------------------------
Dichiarazioni nella form:
Private Sub tv_MouseUp(Button As Integer, Shift As Integer, x As Single,
y As Single)
  Call UnCheck
End Sub
Private Sub tv_NodeCheck(ByVal Node As MSComctlLib.Node)
Set Nod = Node
   If Nod.Text <> "TEI.2" Then
    tv.SetFocus
    Nod.Selected = True
    '   tv.Nodes(Nod.Index).Checked = False
       tv.Nodes(Nod.Index).Selected = True
   End If
End Sub
Private Sub UnCheck()
Dim hItem As Long
hItem = TreeView_GetSelection(m_hwndTV)
If hItem Then
  Call SetTVItemStateImage(m_hwndTV, hItem, 1)
End If
End Sub
 m_hwndTV = tv.hWnd
e naturalmente m_hwndTV è un valore Long
