How to know which row to be selected in CListCtrl for NM_RCLICK event

I write a program that contain a CListCtrl that's style is
WS_VISIBLE|LVS_REPORT|LVS_ALIGNTOP.
During initialization of the program, I create the control here:
if (m_ctlClient.Create(WS_VISIBLE|LVS_REPORT|LVS_ALIGNTOP, ClientArea,
FromHandle(GetSafeHwnd()), 2001))
 {
  LVCOLUMN lv;
  lv.mask = LVCF_FMT|LVCF_WIDTH |LVCF_TEXT ;
  lv.fmt = LVCFMT_BITMAP_ON_RIGHT;
  lv.cx = ClientArea.Width (/2;
  lv.pszText = "ID";
  m_ctlClient.InsertColumn(0, &lv);
  lv.pszText = "Name";
  m_ctlClient.InsertColumn(1, &lv);

 m_ctlClient.InsertItem(1 , "ABC01");
 m_ctlClient.SetItemText(0 , 1, "Anthony");
 m_ctlClient.InsertItem(2 , "ABC02");
 m_ctlClient.SetItemText(1 , 1, "Peter");
 m_ctlClient.InsertItem(3 , "ABC03");
 m_ctlClient.SetItemText(2 , 1, "David");
 }

WHen I try to capture a event of Right click on the CListCtrl,
the event method for right click on the List control is here:
OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
    // TODO: Add your control notification handler code here
     LV_DISPINFO* pLvdi = (LV_DISPINFO*)pNMHDR;
    char chrID[10];
      m_ctlClient.GetItemText(pLvdi->item.mask, 0, chrID, sizeof(chrID)) ;
      char chrName[25];
      m_ctlClient.GetItemText(pLvdi->item.mask, 1, chrName, sizeof(chrName))
;
....
}
I find that the above coding cannot always get the ID and Name correctly?
WHy?
If I right click on the first column of each row, I can successfully get the
ID and name for the clicked row.
But if I don't right click on the first column, I cannot get ID and name
successfully?
How to get the ID and name for the row successsfully when I right click any
column on the row?






-- 
Regards,

Anthony Lam


0
anthony (9)
2/10/2004 1:46:51 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
708 Views

Similar Articles

[PageSpeed] 38

Here try this

void CMyDlg::OnNMRclickList(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

   LVHITTESTINFO lvhti;
   lvhti.pt = pNMLV->ptAction;

   //ask the list control where the cursor was when the right click happened
   if (m_List.SubItemHitTest(&lvhti) != -1)
   {
      CString Temp = m_List.GetItemText(lvhti.iItem,lvhti.iSubItem);
      MessageBox(Temp);
   }
}

Ali R.


"AA" <anthony@jadeflex.com> wrote in message
news:%23PT1Dy97DHA.4060@tk2msftngp13.phx.gbl...
> I write a program that contain a CListCtrl that's style is
> WS_VISIBLE|LVS_REPORT|LVS_ALIGNTOP.
> During initialization of the program, I create the control here:
> if (m_ctlClient.Create(WS_VISIBLE|LVS_REPORT|LVS_ALIGNTOP, ClientArea,
> FromHandle(GetSafeHwnd()), 2001))
>  {
>   LVCOLUMN lv;
>   lv.mask = LVCF_FMT|LVCF_WIDTH |LVCF_TEXT ;
>   lv.fmt = LVCFMT_BITMAP_ON_RIGHT;
>   lv.cx = ClientArea.Width (/2;
>   lv.pszText = "ID";
>   m_ctlClient.InsertColumn(0, &lv);
>   lv.pszText = "Name";
>   m_ctlClient.InsertColumn(1, &lv);
>
>  m_ctlClient.InsertItem(1 , "ABC01");
>  m_ctlClient.SetItemText(0 , 1, "Anthony");
>  m_ctlClient.InsertItem(2 , "ABC02");
>  m_ctlClient.SetItemText(1 , 1, "Peter");
>  m_ctlClient.InsertItem(3 , "ABC03");
>  m_ctlClient.SetItemText(2 , 1, "David");
>  }
>
> WHen I try to capture a event of Right click on the CListCtrl,
> the event method for right click on the List control is here:
> OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult)
> {
>     // TODO: Add your control notification handler code here
>      LV_DISPINFO* pLvdi = (LV_DISPINFO*)pNMHDR;
>     char chrID[10];
>       m_ctlClient.GetItemText(pLvdi->item.mask, 0, chrID, sizeof(chrID)) ;
>       char chrName[25];
>       m_ctlClient.GetItemText(pLvdi->item.mask, 1, chrName,
sizeof(chrName))
> ;
> ...
> }
> I find that the above coding cannot always get the ID and Name correctly?
> WHy?
> If I right click on the first column of each row, I can successfully get
the
> ID and name for the clicked row.
> But if I don't right click on the first column, I cannot get ID and name
> successfully?
> How to get the ID and name for the row successsfully when I right click
any
> column on the row?
>
>
>
>
>
>
> -- 
> Regards,
>
> Anthony Lam
>
>


0
nospam7515 (2085)
2/10/2004 3:40:21 PM
Reply:

Similar Artilces:

Copy 1 Row to Multiple Rows
I have date in one worksheet (A) in rows. I need to reposition the data into another worksheet (B) such that it uses several rows. After entering the formulas once, I want to copy and paste the first set of formula rows in B back into B for each row in A The problem? Lets say I have 1 row of data (A) going into 3 rows of data (B). When I copy the formulas (B), the first row of the new set (row 4)(B) will reference the 4th row of the source data (A) when I want it to reference the second row of the source data (A). The next copy will have the first row (row 7) (B) referencing the 7th row o...

finding row number?
I would like to find the row number of a cell in column A with specific text. Would any one help? =MATCH("text",A:A,0) -- HTH RP (remove nothere from the email address if mailing direct) "james" <james@discussions.microsoft.com> wrote in message news:04215E66-E863-4698-8DE4-575B06375413@microsoft.com... > I would like to find the row number of a cell in column A with specific text. > Would any one help? > james wrote... >I would like to find the row number of a cell in column A with specific >text. > Would any one help? > Hi James, L...

Moving selective data from one sheet to anouther
Hi, I would like to move a range of data within a row from one sheet to anouther sheet automatically when the data in a cell within the range that would be moved, is greater than zero. Is there a formula that will do this? One non-array formulas play which "yields" the desired output .. Assume source table is in Sheet1, cols A to D, data from row2 down, where the key col is col D (the " greater than zero " criteria) Use an empty col to the right, say col E Put in E2: =IF(D2="","",IF(D2>0,ROW(),"")) Copy E2 down to say, E100 to cover the ...

HELP! I KNOW U KNOW HOW TO DO THIS....
i was told there is a way to make certain letters equal numbers. EX. BREADNMILK is 1234567890 / B=1 R=2 and so on. This is so each product has a digit code for the price. EX. EDB = $3.51. I don't know how to do that but my boss said it's possible....THANK-YOU! I have an idea, but I'm not sure I understand what you really want, so I hate to waste the time to produce it. Could you give a few more examples? What are you doing with the data once you figure out a way to make this work? Why BREADNMILK? Is that just an example? You'll use just one word? You're trying to obscu...

Row hieght formula #2
Thanks guys, the filtering worked perfectly -- funktasti ----------------------------------------------------------------------- funktastic's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1600 View this thread: http://www.excelforum.com/showthread.php?threadid=27473 ...

Grouping rows with the plus/minus icon in the first row
I found part of my answer in another post (see below) with the code: ActiveSheet.Outline.SummaryRow = xlAbove ActiveSheet.Range("A2", "A10").Rows.Group But what if I wanted to Group other rows in the same worksheet in the same fashion. For example, I would like to also apply for range A12:A20 with A11 as the row with the +/- sign. And then to A22:A30 with A21 as the row with the +/- sign. And so on.. Also, I am fairly new to using VB, so what would be the entire set of code to place in the in VB editor? Thanks!! http://www.microsoft.com/office/comm...

Row 1 to move when scrolling?
Is there a way to make row i a header row that scrolls down as i do? so i can still see my headers when on row 3 or 300. Sparky Sparky, select cell A2 and window freeze panes -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "Sparky AKA_Sparkticus" <wanw34397_2@blueyonder.co.uk> wrote in message news:vrZbh.10031$k74.2663@text.news.blueyonder.co.uk... > Is there a way to make row i a header row that scrolls down as...

Prevent new pivot table items from being selected
I have a pivot table that contains accounts and reports sales by account. Users selected the accounts they want to see and save their spreadsheet. When new accounts are added to the accounts list, users do not want to see the new accounts. They only want to see the accounts they selected from a previous session when they refresh the pivot table. Does anyone know how to prevent the new accounts from appearing in the pivot table? Thanks! Tom, Use another column: Include, with values of Yes or No, and include it in your pivot table, showing only Yes. Then when new data is added, enter ...

Selection Mode Stuck
I've accidentally put Excel (Office 2003, w/latest updates) into a sticky selection mode on this one spreadsheet file and I can't turn it off. I apparently hit a key combo (I think with a mouse click) and now when I open this file and single click on any cell, that cell is selected and the selection extends in both directions as I move the mouse. I can't click on any buttons, or toolbar icons, or do anything to stop this selecting mode. It just goes on and on, autoscrolling to infinity. I eventually have to CTRL-ALT-DEL to kill Excel, just to free up my computer. Any help wou...

Hide images when Hiding Rows
I have inserted images into cells, but when I hide the column the images are not hidden with that column, they just get squished between the two cells next to the hidden cell. Is there a setting or way to tie the image to that cell so that it hides/unhides appropriately with the row? -- kurt ------------------------------------------------------------------------ kurt's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=35686 View this thread: http://www.excelforum.com/showthread.php?threadid=554712 Kurt You cannot insert an image into a cell. You can overlay ...

XPATH 1.0 select a certain set of attributes and concat them.
I have a the following xml node. <doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/> I would like to output "abc" I have the following XPATH2.0 so far //doc/@*[name()[starts-with(.,'tag')]] which returns a node list. Note that docTag* are ignored and there could be any number of tag*. I managed to get a solution from microsoft.public.xml for concatinating these using string-join function string-join(//doc/@*[starts-with(local-name(), 'tag')], '') however, can something similar be done in XPATH ...

It's Conditional Formatting, Jim, but not as we know it...
Hi, Is there any way of producing the same as a conditional format on a cell (ie. chenge fill and font colours according to a calculated value) but for more than three (four, if you count the default) values? TIA Dave An example '----------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) '----------------------------------------------------------------- Const WS_RANGE As String = "H1:H10" '<=== change to suit On Error GoTo ws_exit: Application.EnableEvents = False If Not Intersect(Targe...

Repeating a Cell Format For Many Rows: What's Fastest Way?
I want to merge adjacent horizontal cells and repeat that in a column for 20 lines. What is a quick way to do that so I don't have to repeat the merge formatting 20 times? Then I want to draw a line along the bottom of each of these merged cells. Again, what is the fastest way to do that? Suppose it was 200 lines. What is the shortcut? Thanks -- TomBrooklyn ------------------------------------------------------------------------ TomBrooklyn's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=7398 View this thread: http://www.excelforum.com/showthrea...

Limit the data selection based on two fields?
Hello, I have a data entry form where user input the data. Within the data fields, I have field call Item, Side, sequence field where any combination of these 3 fields are unique. What I would like to achieve on the sequence field is limit the selected based on selection of Item and Side. This is to prevent user from inputting wrong values on that field. Any help is appreciated. Example fields: Item Side Sequence 11A1300-1 1st side 50 11A1300-1 1st side 100 11A1300-1 1st side 200 11A1300-1 1st side 400 11A1300-1 1st side ...

OWA jumping mouse
I have two computers on my network that are having an interesting issue. When they are creating a message and typing away in the body of the message, randomly when they hit a key, any key, they system will act as if the mouse was clicked. If the mouse is over the send button, it would have sent the email. If the mouse was over the start button, the start menu would have come up. Where ever the mouse was left at, it will act as if it was clicked. It is very random but often. This only happens in OWA, not in outlook or any other place. Both systems are running XP pro SP2 with IE 6 SP2. ...

Not able to select range of cells with mouse.
I am working with Excel 2007 and when I try to select a range of cells, nothing happens. The lovely blue shading is not visible. I first notice this when I tried to select non-adjacent ranges. When I pressed CTRL, then clicked a cell with my mouse, a box appeared inside the cell and that was it. Has anyone seen this before and how do I correct this? Thanks, jen jen If you continue to press CTRL and select other cells, you will see that it's only the last cell selected that doesn't shade (although perhaps not blue). George Gee "jen" <jen@discussions.microsoft...

Do You Know???
Hi... Where to get personal / business loan? How to settle your debt? Where to invest? Monthly Profit 20%? One time investment only? Setup your own business & growing income? The Beneficiary Bank is Barclays Bank? Just only need USD1070 for Financial Freedom? 300% Profit,10%Commission,5% Bonus,1% Revenue & 0.01% Daily Profit Payout!! ---------------------------------------------------------------------------= =AD=AD----- Get me online at : E-Mail /Yahoo Messenger,my ID : sallehes[at]yahoo.com Change [at] to @ If you never take the chance, you will never have the chances. >From O...

How does one copy subtotal rows?
How does one copy subtotal rows? -- Since my access to NNTP is limited, a copy of your reply to ALEXANDEReBARNEs@Yahoo.Com is especially appreciated. Alexander One usually selects the rows he wishes to copy, Then hits <F5>, Then, in the "GoTo" window clicks on "Special", Then, in the "GoToSpecial" window clicks on "VisibleCellsOnly", then <OK>. Now, right click in that selection and choose "Copy", Then navigate and paste to "wherever". -- HTH, RD ------------------------------------------------------------------...

switch colums and rows
Here's my problem...I have a list of bills for workers' comp claimants. Each bill is in a row with a specific service type (occup med center, radiology, surgery, physical therapy). The columns house the claimant name, date of service, a physician name. I need to create a "story" for each claimant showing the number of days between each service transaction (between physician visit and surgery, for example). I was thinking that the best way to do this would be to switch my rows into colums. How would I pull specific rows (I have a column label with the types of service)...

Group Rows without unhiding them!
Hello, you may know what I mean. I have three rows where the 2nd one is hidden. When I apply the group onto those cells they always get unhidden. Do you know how to avoid this? ne0trace The only thing I've ever done tosolve that is to put the 2nd row in another group (nest groups within each other). Then when you expand the 3-row group, you only see rows 1 and 3, and you'd have to expand again in order to see row 2. So this way, row 2 stays hidden until until called for. On 7 Aug., 16:26, tsi...@intelligentsystemsconsulting.com wrote: > The only thing I've ever done tosolve...

What are: "Control Source" , "Row Source" and "Row Source Type" ?
Dear experts, Kindly explain the following terms and functions in MS Access: "Control Source" "Row Source" "Row Source Type" "Column Count" "IME Hold" "IME Mode" Thanks a lot , experts ! -- Allen Phailat Wongakanit "ali" <ali@discussions.microsoft.com> wrote in message news:B2741CBC-BAB0-4DE1-8F00-FF04B1E21A7B@microsoft.com... > Dear experts, > > Kindly explain the following terms and functions in MS Access: > > "Control Source" The field which is the bound source of data for th...

MS POS Crashes several times in a row!
Hi, MS POS 2.0 crashes out of the blue, and when I restart it, it crashes again. After several time going through this restarting/crashing scenarios, it stabilazes until the next time it wants to get crazy (usually several weeks or a few months). I am having in in two seperate stores running independent POS 2.0 systems (w/ SQL 2005 Express). Is there anybody having the same problem? Any advise? Thank you in advance, Dursun ...

how to highlight current row & column automatically by a color #2
I'm using Excel 2003, my question is how to highlight current row & column with a color automatically, to identify my position. Though excel help us by highlighting column & row number, but i want whole column & row to be highlighten to better finding my cell position and all the contents in appropriate row & column. So When I change my cell position, the highlighted row & column move appropriately. See reply to "asif4u"s post In article <26ADDC6F-069B-4DC1-AE96-EA17863835E9@microsoft.com>, "iffi" <iffi@discussions.microsoft.com>...

Combine multiple rows into one row with multiple columns
Hi, I have a table set up so that there are three columns: StudyID, DrawDate, and Value. StudyID and DrawDate are the primary key. I want to create a table from this one that has only one row for each StudyID so that it would go from: StudyID DrawDate Value to StudyID DrawDate1 Value1 DrawDate2 Value2 DrawDate3 Value3 etc. Is there a way to do this? Thanks, Elysia "Elysia Larson" <elysia.larson@gmail.com> wrote in message news:832e952f-174f-489f-ab7a-e2189f660a92@f6g2000vbp.googlegroups.com... > Hi, > > I have a...

Do you know this?
I gonna to purchase Joyfax Server. Do you have any idea about it? 'Joyfax - Fax Server, Fax software, Windows Fax Server, Network Fax Solution, Free Fax Viewer, Fax Broadcasting software' (http://www.joyfax.com) -- lenny66 Posted via http://www.vistaheads.com In article <lenny66.4cslw5@no-mx.forums.vistaheads.com>, lenny66.4cslw5 @no-mx.forums.vistaheads.com says... > What exactly would you imagine yourself seeing subject "Do you know this?" People usually ignore topics with unclear subjects. -- Poutnik The best depends on how the be...