IonicWind Software

Aurora Compiler => GUI => Topic started by: John S on April 26, 2007, 02:30:02 AM

Title: Listview question
Post by: John S on April 26, 2007, 02:30:02 AM
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?
Title: Re: Listview question
Post by: srod on April 26, 2007, 03:21:59 AM
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?
Title: Re: Listview question
Post by: John S on April 26, 2007, 11:47:25 AM
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.
Title: Re: Listview question
Post by: sapero on April 26, 2007, 12:18:44 PM
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;
}
Title: Re: Listview question
Post by: John S on April 26, 2007, 12:51:49 PM
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.
Title: Re: Listview question
Post by: Bruce Peaslee on April 26, 2007, 02:53:45 PM
listview.src in the examples shows how it is done.
Title: Re: Listview question
Post by: srod on April 26, 2007, 03:02:59 PM
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
Title: Re: Listview question
Post by: John S on May 02, 2007, 03:07:45 PM
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;
}
Title: Re: Listview question
Post by: Ionic Wind Support Team on May 02, 2007, 05:25:43 PM
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.
Title: Re: Listview question
Post by: John S on May 02, 2007, 05:29:57 PM
thanks Paul,
I have the listview example that I was looking at.
I'll try out your suggestion.

Title: Re: Listview question
Post by: John S on May 02, 2007, 05:36:45 PM
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);
}
Title: Re: Listview question
Post by: Ionic Wind Support Team on May 02, 2007, 05:43:01 PM
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.
Title: Re: Listview question
Post by: John S on May 02, 2007, 05:59:17 PM
Awesome!!!  it worked.  I had to move the "struct NMLISTVIEW" and I got it to work thanks Paul.