April 24, 2024, 04:06:11 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Listview question

Started by John S, April 26, 2007, 02:30:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John S

I have a few listviews in my app.  How can I allow the user to click on a column heading as if it were a button?
John Siino, Advanced Engineering Services and Software

srod

List views normally carry the required style flag which cause the header cells to act like buttons. Only if you set the style flag LVS_NOSORTHEADER will the header cells not act like buttons etc.

Are you asking how to determine when the user clicked a column header?

John S

Thanks for the response.  Yes, I'm looking for how to determine when and which button was clicked.  I know how to define and use regular button and controls, but I don't know how or what to do with the listviews.
John Siino, Advanced Engineering Services and Software

sapero

John S, in your OnNotify handler for list view, check if the "code" equals to LVNCOLUMNCLICK. If so, the "pnmhdr" points to NMLISTVIEW structure, where iSubItem member identifies the column.
struct NMLISTVIEW {
    NMHDR hdr;
    int iItem;
    int iSubItem; // column index
    UINT uNewState;
    UINT uOldState;
    UINT uChanged;
    POINT ptAction;
    LPARAM lParam;
}

John S

Thanks all,
I will try it out.  Expect questions.  I'll post an example here when I can.
If anyone else has additional info, feel free to add to the discussion.
John Siino, Advanced Engineering Services and Software

Bruce Peaslee

listview.src in the examples shows how it is done.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

srod

You can also catch the HDN_ITEMCLICK notification message which is sent to the listview's window proc.  Only useful though if you have subclassed the list view in question.  :D

John S

Help!

I have tried several variations of code trying to read a button click. 
My program compiles but crashes.  I'm debugging it now.

Can I have OnControl and OnNotify methods running at the same time?
Can I move the OnNotify code into my OnControl method and delete the OnNotify?

Here are some code snippets:

TabDlg::OnInitDialog(), int
{
...

class TabDlg : CDialog
{
declare _TabDlg(); // destructor
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl), int;
declare OnNotify(int code, int nID, NMHDR *pnmhdr), int;
...


// Initialize ListView
pTZList = GetControl(Tab6_LISTVW_2);
pTZList->SetFont( "Monospac821 BT", 10, 400 );
pTZList->InsertColumn( 0,"  Depth(ft)");
pTZList->InsertColumn( 1,"   SL  ");
pTZList->InsertColumn( 2,"  Qb (k)  ");
pTZList->InsertColumn( 3,"  Tm (k)  ");
pTZList->InsertColumn( 4,"  Qt (k)  ");
pTZList->InsertColumn( 5,"  Zb(in)  ");
pTZList->InsertColumn( 6,"  Zt(in)  ");
pTZList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
...



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TabDlg::OnNotify(int code, int nID, NMHDR *pnmhdr), int
{
CListView *pList = GetControl(pnmhdr->idFrom);
if(code = LVNCOLUMNCLICK)
{
select pList->GetColumnText(*(NMLISTVIEW)pnmhdr.iSubItem)
{
case ("   SL  "):
plotSelection = SL;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Stress Level, SL" );

case ("  Qb (k)  "):
plotSelection = QB;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Axial Force, Qb" );

case ("  Tm (k)  "):
plotSelection = TM;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Side Shear, Tm" );

case ("  Qt (k)  "):
plotSelection = QT;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Axial Force, Qt" );

case ("  Zb(in)  "):
plotSelection = ZB;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Displacement, Zb" );

case ("  Zt(in)  "):
plotSelection = ZT;
pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Displacement, Zt" );
}
}

return true;
}
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

When you override OnNotify you have to call the base class version or OnControl won't get called.  Instead of:

return true;

At the end of OnNotify use:

return CDialog!!OnNotify(code, nID, pnmhdr);

And please feel free to use the samples provided with Aurora as a base.

Paul.
Ionic Wind Support Team

John S

thanks Paul,
I have the listview example that I was looking at.
I'll try out your suggestion.

John Siino, Advanced Engineering Services and Software

John S

Do I understand that I should have:

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
CDialog::OnNotify(int code, int nID, NMHDR *pnmhdr), int
{
   CListView *pList = GetControl(pnmhdr->idFrom);
   if(code = LVNCOLUMNCLICK)
   {
      select pList->GetColumnText(*(NMLISTVIEW)pnmhdr.iSubItem)
      {
      case ("   SL  "):
         plotSelection = SL;
         pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Stress Level, SL" );
...
      case ("  Zt(in)  "):
         plotSelection = ZT;
         pTZText[Tab6_NumText-1]->SetText( "Normalized Plot of Displacement, Zt" );
      }
   }

return CDialog!!OnNotify(code, nID, pnmhdr);
}
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

No.  You class is named TabDlg, not CDialog.

TabDlg::OnNotify(int code, int nID, NMHDR *pnmhdr), int
{
...
return CDialog!!OnNotify(code, nID, pnmhdr);
}

You are processing a messge in your class, generated by WM_NOTIFY.  Calling the base class version gives it a chance to process the message as well.  In the case of CDialog it simply calls CWindow!!OnNotify which extracts the control id and other information before calling OnControl in your derived class.

If you don't call the base class version of OnNotify then OnControl will never be called for notification codes.

Paul.
Ionic Wind Support Team

John S

Awesome!!!  it worked.  I had to move the "struct NMLISTVIEW" and I got it to work thanks Paul.
John Siino, Advanced Engineering Services and Software