|
-
February 1st, 2006, 06:27 PM
#1
ClistCtrl - Get DoubleClick Row data
Hi, I've lurked a bit in previous forum but I'm not sure yet.
If ,in a Report view list control ,I want to edit the data of a row after I've DoubleClicked it with left mouse button, how can i do ?
To edit data I would like to make appear a dialog Box that accept the right fields listened.
many thanks.
ciao
-
February 1st, 2006, 07:37 PM
#2
Re: ClistCtrl - Get DoubleClick Row data
First, override the list views NM_DBLCLK command. In the message handler you need to hit test to see if an item on the list was clicked, and if it was, you need to determine which item. Below is the code which does that. This is almost exactly from "Programming windows with MFC"
In the following code, the list view is in a dialog and m_list is a CListView member of the dialog class. If you are using a Doc/View architecture, it shouldn't be difficult to make this code work for that project as well.
Code:
void CMyDialog::OnDoubleClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
DWORD dwPos = ::GetMessagePos ();
CPoint point ((int) LOWORD (dwPos), (int) HIWORD (dwPos));
m_list.ScreenToClient (&point);
int nIndex;
if ((nIndex = m_list.HitTest (point)) != -1) {
// If you are in this if block, that means an item on the list
// was chosen and nIndex is the index of the selected item
// from the list.
// Do whatever you want to do with the selected item
return;
}
*pResult = 0;
}
Good luck.
-
February 4th, 2006, 01:26 PM
#3
Re: ClistCtrl - Get DoubleClick Row data
Many Thanks! It works Fine.
But how can I get the Column where I am in addition to the Row...
ciao
-
February 4th, 2006, 04:40 PM
#4
Re: ClistCtrl - Get DoubleClick Row data
That's straightforward.
Code:
// nIndex is the row index from the list.
// The second argument is the column index. It's 0 based so 0 is for the 1st
// column and 1 is for the second column, etc...
CString strCol1, strCol2;
strCol1 = m_list.GetItemText (nIndex, 0); // Get the 1st column data for the row nIndex
strCol2 = m_list.GetItemText (nIndex, 1); // Get the 2nd column data for row nIndex
-
February 4th, 2006, 06:31 PM
#5
Re: ClistCtrl - Get DoubleClick Row data
For another example, check out this post. This thread has a sample where each list view item is represented by a class object (via the SetItemDataPtr). Also, this is an example of a virtual list-view, which allows efficient display of large lists (see msdn for more on virtual list-views). It also shows how to modify item data and (if I remember correctly), has code to determine the column clicked on.
Arjay
-
August 21st, 2012, 06:59 AM
#6
Re: ClistCtrl - Get DoubleClick Row data
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|