Share via


CTreeCtrl::InsertItem

Llame a esta función para insertar un nuevo elemento en un control de vista de árbol.

HTREEITEM InsertItem(
   LPTVINSERTSTRUCT lpInsertStruct 
);
HTREEITEM InsertItem(
   UINT nMask,
   LPCTSTR lpszItem,
   int nImage,
   int nSelectedImage,
   UINT nState,
   UINT nStateMask,
   LPARAM lParam,
   HTREEITEM hParent,
   HTREEITEM hInsertAfter 
);
HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST 
);
HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   int nImage,
   int nSelectedImage,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST
);

Parámetros

  • lpInsertStruct
    Un puntero a TVINSERTSTRUCT que especifica los atributos del elemento de vista de árbol que se va a insertar.

  • nMask
    Especificar el entero que admite el conjunto.Vea la estructura de TVITEM en Windows SDK.

  • lpszItem
    Dirección de cadena que contiene el texto del elemento.

  • nImage
    Índice del elemento en la lista del control de vista de árbol.

  • nSelectedImage
    Índice de la imagen seleccionada del elemento en la lista del control de vista de árbol.

  • nState
    Especifica los valores para los estados del elemento.Vea los estados del elemento del control de vista de árbol en Windows SDK para una lista de estados adecuados.

  • nStateMask
    Especifica que los estados deben estar establecidas.Vea la estructura de TVITEM en Windows SDK.

  • lParam
    Valor específico de la aplicación de 32 bits asociado al elemento.

  • hParent
    Identificador del elemento primario del elemento insertado.

  • hInsertAfter
    El identificador de elemento detrás del cual se ha del nuevo elemento se va a insertar.

Valor devuelto

Identificador del nuevo elemento si correctamente; si no NULL.

Comentarios

El ejemplo muestra las situaciones en las que puede ser conveniente utilizar cada versión de la función al insertar un elemento del control de árbol.

Ejemplo

// Insert a root item using the structure. We must
// initialize a TVINSERTSTRUCT structure and pass its
// address to the call. 

TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("United States");

HTREEITEM hCountry = m_TreeCtrl.InsertItem(&tvInsert);

// Insert subitems of that root. Pennsylvania is
// a state in the United States, so its item will be a child
// of the United States item. We won't set any image or states,
// so we supply only the TVIF_TEXT mask flag. This
// override provides nearly complete control over the
// insertion operation without the tedium of initializing
// a structure. If you're going to add lots of items
// to a tree, you might prefer the structure override
// as it affords you a performance win by allowing you
// to initialize some fields of the structure only once,
// outside of your insertion loop.

HTREEITEM hPA = m_TreeCtrl.InsertItem(TVIF_TEXT,
   _T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);

// Insert the "Washington" item and assure that it is
// inserted after the "Pennsylvania" item. This override is 
// more appropriate for conveniently inserting items with 
// images.

HTREEITEM hWA = m_TreeCtrl.InsertItem(_T("Washington"),
   0, 0, hCountry, hPA);

// We'll add some cities under each of the states.
// The override used here is most appropriate
// for inserting text-only items.

m_TreeCtrl.InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Altoona"), hPA, TVI_SORT);

m_TreeCtrl.InsertItem(_T("Seattle"), hWA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Yakima"), hWA, TVI_SORT);

Requisitos

encabezado: afxcmn.h

Vea también

Referencia

Clase de CTreeCtrl

Gráfico de jerarquía

CTreeCtrl::DeleteItem

CTreeCtrl::HitTest

CTreeCtrl::SelectDropTarget

CTreeCtrl::GetItem

Tree View Control Reference