Home > Software engineering >  ListCtrl control after the double-click unable to get the line number in addition to the first colum
ListCtrl control after the double-click unable to get the line number in addition to the first colum

Time:10-01

ListCtrl control after the double-click unable to get the line number in addition to the first column
Function is online most of the people use example: (can only get to the line and column number in the first column, click on the second column is always display line Numbers to 1)
 void ParaMeterTool: : OnDblclkList1 (NMHDR * pNMHDR, LRESULT * pResult) 
{
LPNMITEMACTIVATE pNMItemActivate=reinterpret_cast & lt; LPNMITEMACTIVATE> (pNMHDR);
//TODO: add the control notification handler code
/* if (pNMItemActivate - & gt; IItem!=1) */
Listitemdbcl=list_meterdata. GetSelectionMark ();
If (listitemdbcl)
{
CRect the rect, dlgRect;
//get the current column width to fit if the user adjust the width of the
Int width=list_meterdata. GetColumnWidth (pNMItemActivate - & gt; The iSubItem);
List_meterdata. GetSubItemRect (listitemdbcl pNMItemActivate - & gt; LVIR_BOUNDS iSubItem, the rect);

//save selection list items index
//this because two lists public a CEdit control
//so you need to save the list of index
//as well as the corresponding item category index
no.Listdbclicked=1;
/* listitemdbcl=pNMItemActivate - & gt; IItem. */
Listsubitemdbcl=pNMItemActivate - & gt; The iSubItem;
}
* pResult=0;
}

Can't directly obtained with pNMItemActivate, use GetSelectionMark () function also can not get the number of rows in the second column,,
The programming of the listctrl is that there is nothing wrong with watching!
 int line=list_meterdata. GetItemCount (); 
Str_list. The Format (_T (" % 0.2 f), flow_s);
List_meterdata. InsertItem (line, str_list);
For (I=0; I{
Str_list. The Format (_T (" % d "), dt [I]);
List_meterdata. SetItemText (line, I + 1, str_list);
}

CodePudding user response:

Need HitTest?

CodePudding user response:

reference 1st floor schlafenhamster response:
need HitTest?

Get some revised:
 DWORD dwPos=GetMessagePos (); 
CPoint point (LOWORD (dwPos), HIWORD (dwPos));
List_meterdata. ScreenToClient (& amp; Point);

//define structure
LVHITTESTINFO lvinfo;
Lvinfo. Pt=point;

//get the line number information
Int nItem=list_meterdata. HitTest (& amp; Lvinfo);
If (nItem!=1)
{
Listitemdbcl=lvinfo. IItem;//the current line number

Click on the second column is 1

CodePudding user response:

refer to the original poster bingbaobei response:
ListCtrl control after the double-click unable to get the line number in addition to the column 1
Function is online most of the people use example: (can only get to the line and column number in the first column, click on the second column is always display line Numbers to 1)
 void ParaMeterTool: : OnDblclkList1 (NMHDR * pNMHDR, LRESULT * pResult) 
{
LPNMITEMACTIVATE pNMItemActivate=reinterpret_cast & lt; LPNMITEMACTIVATE> (pNMHDR);
//TODO: add the control notification handler code
/* if (pNMItemActivate - & gt; IItem!=1) */
Listitemdbcl=list_meterdata. GetSelectionMark ();
If (listitemdbcl)
{
CRect the rect, dlgRect;
//get the current column width to fit if the user adjust the width of the
Int width=list_meterdata. GetColumnWidth (pNMItemActivate - & gt; The iSubItem);
List_meterdata. GetSubItemRect (listitemdbcl pNMItemActivate - & gt; LVIR_BOUNDS iSubItem, the rect);

//save selection list items index
//this because two lists public a CEdit control
//so you need to save the list of index
//as well as the corresponding item category index
no.Listdbclicked=1;
/* listitemdbcl=pNMItemActivate - & gt; IItem. */
Listsubitemdbcl=pNMItemActivate - & gt; The iSubItem;
}
* pResult=0;
}

Can't directly obtained with pNMItemActivate, use GetSelectionMark () function also can not get the number of rows in the second column,,
The programming of the listctrl is that there is nothing wrong with watching!
 int line=list_meterdata. GetItemCount (); 
Str_list. The Format (_T (" % 0.2 f), flow_s);
List_meterdata. InsertItem (line, str_list);
For (I=0; I{
Str_list. The Format (_T (" % d "), dt [I]);
List_meterdata. SetItemText (line, I + 1, str_list);
}


LVS_EDITLABELS display character of node can be edited, editable for report style for the first column, related to the didn't? How to get the number of rows in the second column

CodePudding user response:

 void CxxxxDlg: : OnRdblclkDatabase (NMHDR * pNMHDR, LRESULT * pResult) 
{//listctrl
//TODO: Add your the control notification handler code here
//find the list item
CPoint pt;
The GetCursorPos (& amp; Pt);
The ScreenToClient (& amp; Pt);
MapWindowPoints (& amp; M_DataList, & amp; Pt, 1);
//afxDump//
LVHITTESTINFO Info;
Info. Pt=pt;
The Info. The flags=LVHT_ONITEM;
Int Item=m_DataList. SubItemHitTest (& amp; Info);
AfxDump
* pResult=0;
}

  • Related