Basic CListView example 
Author Message
 Basic CListView example

Does anyone have (or know of) an extremely basic example of setting up a
CListView in report mode, settting up 3 or 4 columns and filling in some
data?

I'm kinda stuck.  I've got a CListView(CListCtrl) in LVS_REPORT mode and
I have 4 columns setup... But every call I try to make to InsertItem is
failing (ret = 0).  I cannot figure out why.

I don't care about the other views.  If I can help it, I don't care
about images/states.  Just text.

...Matt



Mon, 27 Mar 2000 03:00:00 GMT  
 Basic CListView example

Here is an example for your problem. (Only text)

// This part sets up your Columns in your Reort View

   LV_COLUMN lvColumn;

   lvColumn.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH|LVCF_SUBITEM;        
   lvColumn.fmt = LVCFMT_LEFT;      

   for (  i = 0; i <4; ++i)
   {
      lvColumn.cx = 50;  

      switch ( i)
           {    

         case 0:
            lvColumn.pszText = "Column 1";
            lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
            break;

         case 1:
            lvColumn.pszText =  "Column 2";
            lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
            break;

         case 2:
            lvColumn.pszText =  "Column 3";
            lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
            break;

         case 3:
            lvColumn.pszText =  "Column 4";
            lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
            break;
      }

      m_lvwReport.InsertColumn( i, &lvColumn);

// NOW INSERT THE ROWS

   LV_ITEM pItem;

   pItem.mask = LVIF_TEXT;        
   for ( int i = 0; i < NUMBEROFROWS; ++i)
   {
         pItem.iItem = i;
         pItem.iSubItem = 0;
         pItem.pszText =  "Item in Column 1 " ;    
         pItem.cchTextMax = _tcslen(pItem.pszText);
         m_lvwReport.InsertItem(&pItem);

         for ( int j = 1; j <=3; ++j)
         {
            pItem.iSubItem = j;

            switch( j)
            {
              case (1) :
                  pItem.pszText =  "Item in Column 2 ";    
                  pItem.cchTextMax = _tcslen(pItem.pszText);
              break;

                  case (2) :
                  pItem.pszText =  "Item in Column 3 " ;    
                  pItem.cchTextMax = _tcslen(pItem.pszText);
              break;

                  case (3) :
                  pItem.pszText =  "Item in Column 4 " ;    
                  pItem.cchTextMax = _tcslen(pItem.pszText);
              break;
            }  // switch
            m_lvwReport.SetItem(&pItem);            
         }   // for loop - j
      }  // for loop - i  



Quote:
> Does anyone have (or know of) an extremely basic example of setting up a
> CListView in report mode, settting up 3 or 4 columns and filling in some
> data?

> I'm kinda stuck.  I've got a CListView(CListCtrl) in LVS_REPORT mode and
> I have 4 columns setup... But every call I try to make to InsertItem is
> failing (ret = 0).  I cannot figure out why.

> I don't care about the other views.  If I can help it, I don't care
> about images/states.  Just text.

> ...Matt



Mon, 27 Mar 2000 03:00:00 GMT  
 Basic CListView example

Why dont you check out DAOVIEW sample that came along with VC++.. That
uses List view extensively and in report mode..

Quote:

> Does anyone have (or know of) an extremely basic example of setting up a
> CListView in report mode, settting up 3 or 4 columns and filling in some
> data?

> I'm kinda stuck.  I've got a CListView(CListCtrl) in LVS_REPORT mode and
> I have 4 columns setup... But every call I try to make to InsertItem is
> failing (ret = 0).  I cannot figure out why.

> I don't care about the other views.  If I can help it, I don't care
> about images/states.  Just text.

> ...Matt

--
Girish Bharadwaj
Software developer
http://members.tripod.com/~GBharadwaj/index.html




Mon, 27 Mar 2000 03:00:00 GMT  
 Basic CListView example



Quote:
>Does anyone have (or know of) an extremely basic example of setting up a
>CListView in report mode, settting up 3 or 4 columns and filling in some
>data?

Here's a nice simple example from one of my programs. This is a list
view in a dialog whose "control name" is "m_List":

        // Use the ANSI proportional font for the list.

        HFONT hFont = (HFONT)::GetStockObject(ANSI_VAR_FONT);
        m_List.SetFont( CFont::FromHandle(hFont) );

        CClientDC dc(&m_List);
        dc.GetTextMetrics(&tm);

        // Set up the columns.

        m_List.InsertColumn( 0, "Name" );
        m_List.SetColumnWidth( 0, 10*tm.tmAveCharWidth );

        m_List.InsertColumn( 1, "Object Type" );
        m_List.SetColumnWidth( 1, 14*tm.tmAveCharWidth );

        m_List.InsertColumn( 2, "Mag", LVCFMT_RIGHT );
        m_List.SetColumnWidth( 2, 5*tm.tmAveCharWidth );

        m_List.InsertColumn( 3, "Size" );
        m_List.SetColumnWidth( 3, 10*tm.tmAveCharWidth );

        m_List.InsertColumn( 4, "RA", LVCFMT_RIGHT );
        m_List.SetColumnWidth( 4, 12*tm.tmAveCharWidth );

        m_List.InsertColumn( 5, "Dec", LVCFMT_RIGHT );
        m_List.SetColumnWidth( 5, 11*tm.tmAveCharWidth );

        // Insert the data into the list.

        for (i=0; i<DeepSkyList.GetSize(); i++)
        {
                // Add the name, and store the index that the object has
been
                // inserted at.

                int nIndex = m_List.InsertItem( i, DeepSkyList[i].szName
);

                // Store the array index as the item data.

                m_List.SetItemData( nIndex, i );

                // Object type.

                m_List.SetItemText( nIndex, 1, DeepSkyList[i].szType );

                ....

        }

ie - use "InsertItem" to insert the new "row" in the list; this fills in
the first column. Then use "SetItemText" to enter the data into columns
1, 2, 3, etc.

Chris

----------------------------------------------------------------
Chris Marriott, Microsoft Certified Solution Developer.

Visit our web site at http://www.skymap.com



Mon, 27 Mar 2000 03:00:00 GMT  
 Basic CListView example

I have some examples of setting up list controls that aren't nearly as
complicated as what Microsoft would have you use.  If the original
poster would like to e-mail me, I'd be happy to send them along.

->Brian K. Hughes
Applied Intellect

Quote:



>  Here is an example for your problem. (Only text)

>  // This part sets up your Columns in your Reort View

>     LV_COLUMN lvColumn;

>     lvColumn.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH|LVCF_SUBITEM;
>     lvColumn.fmt = LVCFMT_LEFT;

>     for (  i = 0; i <4; ++i)
>     {
>        lvColumn.cx = 50;

>        switch ( i)
>            {

>           case 0:
>              lvColumn.pszText = "Column 1";
>              lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
>              break;

>           case 1:
>              lvColumn.pszText =  "Column 2";
>              lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
>              break;

>           case 2:
>              lvColumn.pszText =  "Column 3";
>              lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
>              break;

>           case 3:
>              lvColumn.pszText =  "Column 4";
>              lvColumn.cchTextMax = _tcsclen( lvColumn.pszText);
>              break;
>        }

>        m_lvwReport.InsertColumn( i, &lvColumn);

>  // NOW INSERT THE ROWS

>     LV_ITEM pItem;

>     pItem.mask = LVIF_TEXT;
>     for ( int i = 0; i < NUMBEROFROWS; ++i)
>     {
>           pItem.iItem = i;
>           pItem.iSubItem = 0;
>           pItem.pszText =  "Item in Column 1 " ;
>           pItem.cchTextMax = _tcslen(pItem.pszText);
>           m_lvwReport.InsertItem(&pItem);

>           for ( int j = 1; j <=3; ++j)
>           {
>              pItem.iSubItem = j;

>              switch( j)
>              {
>               case (1) :
>                    pItem.pszText =  "Item in Column 2 ";
>                    pItem.cchTextMax = _tcslen(pItem.pszText);
>               break;

>                    case (2) :
>                    pItem.pszText =  "Item in Column 3 " ;
>                    pItem.cchTextMax = _tcslen(pItem.pszText);
>               break;

>                    case (3) :
>                    pItem.pszText =  "Item in Column 4 " ;
>                    pItem.cchTextMax = _tcslen(pItem.pszText);
>               break;
>              }  // switch
>              m_lvwReport.SetItem(&pItem);
>           }   // for loop - j
>        }  // for loop - i



> > > Does anyone have (or know of) an extremely basic example of
> setting up
> a
> > > CListView in report mode, settting up 3 or 4 columns and filling
> in
> some
> > > data?

> > > I'm kinda stuck.  I've got a CListView(CListCtrl) in LVS_REPORT
> mode
> and
> > > I have 4 columns setup... But every call I try to make to
> InsertItem is
> > > failing (ret = 0).  I cannot figure out why.

> > > I don't care about the other views.  If I can help it, I don't
> care
> > > about images/states.  Just text.

> > > ...Matt



Sat, 01 Apr 2000 03:00:00 GMT  
 Basic CListView example

Quote:

> Does anyone have (or know of) an extremely basic example of setting up a
> CListView in report mode, settting up 3 or 4 columns and filling in some
> data?

> I'm kinda stuck.  I've got a CListView(CListCtrl) in LVS_REPORT mode and
> I have 4 columns setup... But every call I try to make to InsertItem is
> failing (ret = 0).  I cannot figure out why.

> I don't care about the other views.  If I can help it, I don't care
> about images/states.  Just text.

> ...Matt

in a very simple way but you may be limited later:

CString test[1][4] = {test1, test2, test3, test4};

m_ListCtrl.InsertItem(  i,(LPCTSTR)test[0][0],0);
m_ListCtrl.SetItemText( i, 1, (LPCTSTR)test[0][1] );
m_ListCtrl.SetItemText( i, 2, (LPCTSTR)test[0][2] );
m_ListCtrl.SetItemText( i, 3, (LPCTSTR)test[0][3] );

//where i is the row



Sun, 02 Apr 2000 03:00:00 GMT  
 Basic CListView example

hi John,

... without trying to patronize you. ;)

Quote:
>CString test[1][4] = {test1, test2, test3, test4};
>m_ListCtrl.InsertItem(  i,(LPCTSTR)test[0][0],0);
>m_ListCtrl.SetItemText( i, 1, (LPCTSTR)test[0][1] );

CString pcsTest[]= {"item", "col1", "col2", "col3", "col4"};

int iItem= m_ListCtrl.InsertItem (0, pcsTest[0]);
m_ListCtrl.SetItemText (iItem, 1, pcsTest[1]);
m_ListCtrl.SetItemText (iItem, 2, pcsTest[2]);
m_ListCtrl.SetItemText (iItem, 3, pcsTest[3]);
m_ListCtrl.SetItemText (iItem, 4, pcsTest[4]);

Note the easier (and much more compilable <veg>) definition of
CStrings. And furthermore I'd never ever trust the list control to
really insert the item at the position I told him. <veg>

... but then, just my two cents. ;)

Carsten Witte

book&data GmbH, Reventloustra?e 5, 24235 Laboe, Germany
 - Human : +49 (4343) 427713
 - Fox   : +49 (4343) 427721
 - Spider: http://www.bookdata.de

  Nothing in live is ever easy. (Calvin)



Tue, 04 Apr 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. CListView and CListCtrl (basic question)

2. MRU, CListView example

3. CListView Reflected message(s) example anywhere?

4. Lex and yacc basic examples

5. Need basic C programming examples.

6. Proposal: alt.binaries.examples.vb4 , alt.binaries.examples.vcpp , alt.binaries.examples.java

7. Tiny Basic/Small Basic C source

8. BASIC to C translator wanted (or BASIC interpreter)

9. Basic->Pascal or Basic->C

10. HELP: CLISTView, Clistctrl

11. Need to speed up construction of large CListViews

12. How connect CListView to DAO source?

 

 
Powered by phpBB® Forum Software