Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ListView_InsertItem - Failed

Posted on 2003-12-02
7
Medium Priority
?
874 Views
Last Modified: 2013-11-20
Dear Experts,

I am trying to insert a new item into a ListView control.

The following code failes...

LVITEM stLVI;
char   szBuf[6];
memset(szBuf, '\0', sizeof(szBuf));
strcpy(szBuf,"Hello");
stLVI.pszText = szBuf;
stLVI.cchTextMax = sizeof(szBuf);
stLVI.iItem = 0;
stLVI.iSubItem = 0;
stLVI.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
stLVI.iImage = 2;
stLVI.lParam = 0;
ListView_InsertItem(listViewWindow,&stLVI);

Any suggestion?

Thanks in advance.

Regards
Anbuselvan
0
Comment
Question by:Anbuselvan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 23

Assisted Solution

by:Roshan Davis
Roshan Davis earned 1500 total points
ID: 9864197
Which style of list you are using ... "Report Style", if yes, before adding the Item you have to add the Column first... like this

      HWND listViewWindow = GetDlgItem(IDC_LIST1)->m_hWnd;

      // Add columns
      LVCOLUMN lvColumn;
      char szLabel[50];
    lvColumn.mask = LVCF_TEXT|LVCF_WIDTH;
    lvColumn.cx = 125;
    lvColumn.pszText = szLabel;

    // Column 0
    strcpy(szLabel,"Column 1");
    ListView_InsertColumn(listViewWindow,0,&lvColumn);


      LVITEM stLVI;
      char   szBuf[6];
      memset(szBuf, '\0', sizeof(szBuf));
      strcpy(szBuf,"Hello");
      stLVI.pszText = szBuf;
      stLVI.cchTextMax = sizeof(szBuf);
      stLVI.iItem = 0;
      stLVI.iSubItem = 0;
      stLVI.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
      stLVI.iImage = 2;
      stLVI.lParam = 0;
      ListView_InsertItem(listViewWindow,&stLVI);

Good Luck
0
 

Author Comment

by:Anbuselvan
ID: 9865198
Hi roshmon,

  Thanks for your immediate suggestion.

  But, I have already three columns in my report style listview.

  The given is working fine in my dialog based application with listview control.

  But, I am doing one hook application. I need to hook one theird party application and
  clear the list items and add a new item into that.

  Here, I am facing the problem that I have mentioned.

  Any suggestion?

Thanks in advance.

Regards,
Anbuselvan
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 1500 total points
ID: 9865277
Then you have to subclass that listcontrol and add strings

These links might help you

http://www.codeproject.com/dll/subhook.asp - Cross Process Subclassing
http://www.codeproject.com/threads/winspy.asp - Three Ways to Inject Your Code into Another Process

Good luck
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Anbuselvan
ID: 9880698
Hi roshmon,

The given links are very useful. Thanks.

Actually my code is working fine.

But, what I notised is wrong.

The given value is inserted successfully in the list control. But, it is not visibled. So, that I couldn't realised.

I can get the list count = 1.

But, I couldn't see the values in the list control.

Any possible reason?

Thanks.

Regards,
Anbu
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9881051
Probably string that you are giving becoming out of scope.
I'm checking on that....
Rosh :)
0
 

Expert Comment

by:ArchMD
ID: 9995215
Hi,

Have you  created the resource using the resource editor?
If so in the general page of the properties of the control there is an checkbox called visible.
Make sure that is ticked.
Even if you are creating the control dynamically then also during create you have to specify the VISIBLE style.

Regards,
ArchMD
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question