IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

selection d une ligne dans une listview c++win32


Sujet :

C++

  1. #1
    Candidat au Club
    Homme Profil pro
    etudiant
    Inscrit en
    Février 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : etudiant

    Informations forums :
    Inscription : Février 2017
    Messages : 2
    Points : 3
    Points
    3
    Par défaut selection d une ligne dans une listview c++win32
    Bonjour, jai creer une listview comme suit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    // Create the list view window that starts out in report view
    		// and allows label editing.
    		hWndList = CreateWindowEx(0L,
    			WC_LISTVIEW,                // list view class
    			"",                         // no default text
    			WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | WS_EX_CLIENTEDGE,
    			30, 75,
    			260, 300,
    			hWnd,
    			(HMENU)ID_LISTVIEW,
    			NULL,
    			NULL);
     
     
    		ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
     
    		LV_COLUMN lvC;      // List View Column structure
    		char szText[MAX_PATH];    // Place to store some text
     
    		lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
    		lvC.fmt = LVCFMT_LEFT;  // left align the column
     
    		lvC.cx = 75;// width of the column, in pixels
    		lvC.pszText = "colonneA";
    		ListView_InsertColumn(hWndList, 0, &lvC);
     
    		lvC.pszText = "colonneB";
    		ListView_InsertColumn(hWndList, 1, &lvC);
     
    		lvC.pszText = "colonneC";
    		ListView_InsertColumn(hWndList, 2, &lvC);
     
    		lvC.pszText = "colonneD";
    		ListView_InsertColumn(hWndList, 3, &lvC);
     
    		lvC.pszText = "colonneE";
    		ListView_InsertColumn(hWndList, 4, &lvC);
     
     
    		// load a random item in memory
    		ListViewDATA[0].colonneA = 2;
    		ListViewDATA[0].colonneB = 5673920485;
    		ListViewDATA[0].colonneC = 50;
    		ListViewDATA[0].colonneD = 456789;
    		ListViewDATA[0].colonneE = 345;
     
    		int iSubItem;
    		LV_ITEM lvI;
    		lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
    		lvI.state = 0;
    		lvI.stateMask = 0;
    		lvI.iItem = 0;
    		lvI.iSubItem = 0;
     
    		lvI.pszText = LPSTR_TEXTCALLBACK;
    		lvI.cchTextMax = 64;
    		lvI.lParam = (LPARAM)&ListViewDATA[0];
     
    		ListView_InsertItem(hWndList, &lvI);
    		for (iSubItem = 1; iSubItem < 5; iSubItem++)
    		{
    			ListView_SetItemText(hWndList,
    				0,// = lvI.iItem
    				iSubItem,
    				LPSTR_TEXTCALLBACK);
    		}
    et la gere avec le msg WM_NOTIFY comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    case WM_NOTIFY:
    	{
    		LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
    		NM_LISTVIEW *pNm = (NM_LISTVIEW *)lParam;
    		LISTVIEWSTRUCT *pListviewdata = (LISTVIEWSTRUCT *)(pLvdi->item.lParam);
    		static TCHAR szText[10];
     
    		if (wParam == ID_LISTVIEW)
    		{
    			switch (pLvdi->hdr.code)
    			{
    			case LVN_GETDISPINFO:
    				switch (pLvdi->item.iSubItem)
    				{
    				case 0:
    					sprintf(szText, "%u", pListviewdata->colonneA);
    					pLvdi->item.pszText = szText;
    					break;
     
    				case 1:
    					sprintf(szText, "%u", pListviewdata->colonneB);
    					pLvdi->item.pszText = szText;
    					break;
     
    				case 2:
    					sprintf(szText, "%u", pListviewdata->colonneC);
    					pLvdi->item.pszText = szText;
    					break;
     
    				case 3:
    					sprintf(szText, "%u", pListviewdata->colonneD);
    					pLvdi->item.pszText = szText;
    					break;
     
    				case 4:
    					sprintf(szText, "%u", pListviewdata->colonneE);
    					pLvdi->item.pszText = szText;
    					break;
     
    				default:
    					break;
    				}
    				break;
     
    			default:
    				break;
    			}
     
    		}
    	}
    	break;


    la listview saffiche correctement mais il mest impossible de selectionner une ligne, meme en utilisant "ListView_SetItemState".
    Comment faire ?

    merci davance

  2. #2
    Candidat au Club
    Homme Profil pro
    etudiant
    Inscrit en
    Février 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : etudiant

    Informations forums :
    Inscription : Février 2017
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    En ajoutant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    default:
    return CDRF_DODEFAULT;
    break;
    dans le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    switch (pLvdi->hdr.code)
    je peux maintenant selectionner les lignes manuellement.

    seulement il est aussi possible dediter les lignes alors que je ne precise pas le type LVS_EDITLABELS.

    est ce que cest du au "CDRF_DODEFAULT" qui va gerer les msg labeledit par defaut ?

    si oui comment est ce que je dois gerer le msg NM_CLICK pour eviter davoir a appeler CDRF_DODEFAULT?

    merci davance

Discussions similaires

  1. Réponses: 15
    Dernier message: 21/10/2009, 13h31
  2. Réponses: 4
    Dernier message: 15/10/2009, 13h33
  3. [E-00] Syntaxe pour insérer une ligne ou une colonne dans une feuille
    Par Benjycool dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 02/02/2009, 09h27
  4. [MySQL] inserer une ligne d'une table dans une autre table
    Par piero53 dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 14/12/2008, 18h29
  5. Réponses: 3
    Dernier message: 29/01/2008, 12h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo