Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I have a CListCtrl dervied class in which I have created 3 column .Now when adding first row using InsertItem and then setting text to each one of these columns I can display the row .
Now I am again setting the text for its already available list ctrl item index but this time the text is not getting updated .

I am using listCtrl.SetItemText() api .
I tried using Update(),UpdateData() api's but none of them worked .

it is like :
sr.no Input Output Status
1 file.txt file.ext In progress

So the case is like this listctrl showns the status of the file being exported now once exported I have to set this status to ' Completed '
So when I m doing so it is not changing the text.

sr.no Input Output Status
1 file.txt file.ext Completed
This is what I want .


Can somebody tell me how to go about it.

What I have tried:

I tried update , updatadata api.
Posted
Updated 16-Nov-17 21:03pm
Comments
Richard MacCutchan 17-Nov-17 4:23am    
Please show your code.

1 solution

Check the return value of CListCtrl::SetItemText[^]. If that is FALSE, check if you passed valid nItem (row) and nSubItem (column) parameters.

Assuming it is the first row and Status is the 4th column it should be:
C++
VERIFY(listCtrl.SetItemText(0, 3, _T("Completed")));
The VERIFY macro will raise an assertion in debug builds when the call returns FALSE and does nothing in release builds.

If the call succeeds there is no need to update the list because that will be done by the call if redrawing is not disabled. Or did you call listCtrl.SetRedraw(FALSE) before and forgot to re-enable redrawing?
 
Share this answer
 
Comments
iampradeepsharma 17-Nov-17 3:48am    
there is some issue I guess as when I put some message box soon after setitemtext displaying the return value of setitemtext it shows the text in that status column and when I remove the messagebox it does not show then ? Is there any refresh window sortof issue ?
Jochen Arndt 17-Nov-17 4:23am    
If the cell content is shown updated while the message box is opened and not anymore when the mesage box is closed, there is only one possible reason:

Somewhere in your code the item is updated again with the old value afterwards. There are no system activities that will change items in the background. They are only changed by code written by you.

But you did not show any code or even told us from where (prtobably some handler) you are updating the item.
iampradeepsharma 17-Nov-17 4:28am    
No even after I click on the ok button of messagebox the text remains there . Only in the case when the messagebox is not in place I do not get to see the text in the status column.
Jochen Arndt 17-Nov-17 4:41am    
OK. So the message box triggers a repaint of the list. Under normal conditions setting the item text will invalidate the list window (or a portion of it) and update the window when idle.

To force repainting of the whole list use
Invalidate();
UpdateWindow();

But that should not be necessary in most cases.

Again: From where do you update the item?
Is it be called / triggered from another thread or an asynchronous event like from file operations?

Then it might be necessary to force redrawing. But note that updating GUI elements upon such events must be handled properly (there are some pitfalls).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900