victorcoasne
Messages postés1101Date d'inscriptionjeudi 24 avril 2003StatutMembreDernière intervention23 juillet 2023
-
18 avril 2005 à 19:43
victorcoasne
Messages postés1101Date d'inscriptionjeudi 24 avril 2003StatutMembreDernière intervention23 juillet 2023
-
22 avril 2005 à 23:40
Bonjour,
J'ai une ListView et quand je met le style LVS_EDITLABELS je peux éditer ce champs !
Seulement voilà j'ai une ListView avec LVS_REPORT comme style et
l'édition ne peut se faire que sur la première colone et non les autres
!
Je voudrais donc savoir comment pouvoir éditer tous les champs (toutes les colones) alors que je suis en style LVS_REPORT.
//***************************************************************************************
//***************************************************************************************
LRESULT CALLBACK ListViewProc(HWND hCtrl, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
// mise à jour de l'Edit ou début d'un nouvel Edit
case WM_LBUTTONDOWN :
if(g_hListViewEdit != NULL)
UpdateEditItemData();
else
OnListViewLButtonDown(wParam, LOWORD(lParam), HIWORD(lParam));
break;
// mise à jour de l'Edit
case WM_HSCROLL : // no break
case WM_VSCROLL :
if(g_hListViewEdit != NULL)
UpdateEditItemData();
break;
}
//***************************************************************************************
//***************************************************************************************
void OnListViewLButtonDown(UINT nFlags, short x, short y)
{
// nombre d'items au total
int nTotalCount = SendMessage(g_hListView, LVM_GETITEMCOUNT, 0, 0);
// premier item visible
int nFirstVisible = SendMessage(g_hListView, LVM_GETTOPINDEX, 0, 0);
// on recherche sur qu'elle ligne se trouve la souris
for(int nLine = nFirstVisible; nLine < nFirstVisible+nVisibleCount; nLine++)
{
// rectangle entourrant la ligne à tester
RECT rcLine;
rcLine.left = LVIR_BOUNDS;
SendMessage(g_hListView, LVM_GETITEMRECT, nLine, (LPARAM)&rcLine);
// si la souris n'est pas dans ce rectangle, on continue
POINT pt = {x, y};
if(!PtInRect(&rcLine, pt))
continue;
// recherche du numéro de la colonne ou se trouve la souris
int x0 = 0;
int nColumn = 0;
int nColumnWidth;
while(nColumn < COLUMN_COUNT)
{
nColumnWidth = SendMessage(g_hListView, LVM_GETCOLUMNWIDTH, nColumn, 0);
if(x >= x0 && (x < x0+nColumnWidth))
break;
x0 += nColumnWidth;
nColumn++;
}
// création d'une zone d'édition
g_hListViewEdit = CreateWindowEx(0, "EDIT", "", WS_BORDER|WS_VISIBLE|WS_CHILD,
x0, rcLine.top, nColumnWidth, rcLine.bottom- rcLine.top,
g_hListView, NULL, g_hAppInstance, NULL);
// changement de la police de caractères
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(g_hListViewEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
// on affiche le texte, on le sélectionne et on donne le focus
SetFocus(g_hListViewEdit);
SetWindowText(g_hListViewEdit, szText);
SendMessage(g_hListViewEdit, EM_SETSEL, 0, -1);
}
}
//***************************************************************************************
//***************************************************************************************
void UpdateEditItemData()
{
// récupération du texte rentré dans la zone d'édition
char szText[256];
GetWindowText(g_hListViewEdit, szText, 256);
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 323
TOPMARGIN, 7
BOTTOMMARGIN, 223
END
END
#endif // APSTUDIO_INVOKED
#endif // French (France) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by EditListView.rc
//
#define IDD_MAIN 101
#define IDC_LISTVIEW 1000
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
ymca2003
Messages postés2070Date d'inscriptionmardi 22 avril 2003StatutMembreDernière intervention 3 juillet 20067 19 avril 2005 à 09:04
Si je me souviens bien c'est pas possible directement, il faut sous-classer la list-view, détecter le clic souris, récupérer le rectangle de l'item à cet endroit ainsi que l'indice de l'item (pas simple selon mes souvenirs), créer un Edit et lui donner le focus. Détruire cet Edit lors de la perte du focus, appui sur Entrer ou Echap (après avoir sauvegarder le contenu) et affecter le résultat à l'item.
J'avais fait un truc du genre il y a pas mal de temps, je pourrais sans doute le retrouver.
Si quelqu'un a plus simple, je suis également preneur...