From: Rich on
Hi guys,

I am using listView on Dialog and need to refresh it with a button, the
following is the code.

void CMyList::OnBnClickedRun(int ix, float x)
{
CString str;
m_myList.InsertColumn(0, "Name1", LVCFMT_LEFT, 100);
m_myList.InsertColumn(1, "Name2", LVCFMT_LEFT, 100);

m_myList.DeleteAllItems();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT | LVIF_STATE;
lvItem.state = 0;
lvItem.stateMask = 0;
str.Format(" %d", ix);
m_myList.InsertItem(0, str);
str.Format("%3.1f", x);
m_myList.SetItemText(0, 1, str);

}

When I first click the refresh button, everything is alright. But when I
click the button again, I always get a message

The exception Breakpoint
A breakpoint has been reached....

When click cancel to debug it, I always get to here

#undef _CrtDbgBreak

_CRTIMP void _cdecl _CrtDbgBreak(
void
)
{
DebugBreak();
}

Any body has some idea what's wrong with my code? Many thanks!

rich
From: Scott McPhillips [MVP] on
Rich wrote:
> Hi guys,
>
> I am using listView on Dialog and need to refresh it with a button, the
> following is the code.
>
> void CMyList::OnBnClickedRun(int ix, float x)
> {
> CString str;
> m_myList.InsertColumn(0, "Name1", LVCFMT_LEFT, 100);
> m_myList.InsertColumn(1, "Name2", LVCFMT_LEFT, 100);
>
> m_myList.DeleteAllItems();
> LV_ITEM lvItem;
> lvItem.mask = LVIF_TEXT | LVIF_STATE;
> lvItem.state = 0;
> lvItem.stateMask = 0;
> str.Format(" %d", ix);
> m_myList.InsertItem(0, str);
> str.Format("%3.1f", x);
> m_myList.SetItemText(0, 1, str);
>
> }
>
> When I first click the refresh button, everything is alright. But when I
> click the button again, I always get a message
>
> The exception Breakpoint
> A breakpoint has been reached....
>
> When click cancel to debug it, I always get to here
>
> #undef _CrtDbgBreak
>
> _CRTIMP void _cdecl _CrtDbgBreak(
> void
> )
> {
> DebugBreak();
> }
>
> Any body has some idea what's wrong with my code? Many thanks!
>
> rich

Why are you inserting (again!) the first two columns each time?

To analyze the debug break study the stack window when you hit the
break. This window will lead you back to the exact line in your code
that caused the problem. Also check the output window to see if the CRT
has sent you an error message.

--
Scott McPhillips [VC++ MVP]

From: Rich on
Thanks Scott.

I put some edit boxes to input data and listView to output the results on a
Dialog. So when I make some change in the input, I want to get a new list of
results. I've tried a few things:
1. to avoid re-inserting the headers, I jump the two lines in second times
and thereafter, error will appear at the first inserting of item;
2. use deleteAll() to clear current listView and write again, error appears
at the delete line;

But in the same program, I used a similar listView in a formView class and
it works well. Really strange.

Thanks again.
rich

"Scott McPhillips [MVP]" wrote:

>
> Why are you inserting (again!) the first two columns each time?
>
> To analyze the debug break study the stack window when you hit the
> break. This window will lead you back to the exact line in your code
> that caused the problem. Also check the output window to see if the CRT
> has sent you an error message.
>
> --
> Scott McPhillips [VC++ MVP]
>
>
From: Joseph M. Newcomer on
This is a pretty useless error report.

What is the call stack? This is critical. It may well be that what you are seeing is heap
damage caused by some other malfunction in your program. In this case, the line that
detects the problem (which is what you are possibly seeing) is completely unrelated to the
code that CAUSED the problem. But without the critical call stack traceback, it is
impossible to tell what is going on, because ALL breaks caused by various error conditions
go to CrtDbgBreak, so that is completely meaningless. It is also meaningless to know that
it came from your list insert code, unless we know the execution path between the two
events.

Given the detail you have provided, the only possible answer to what is wrong with your
program is "your program is broken".

Why aren't you setting the columns once in OnInitDialog? Then you don't have to do
anything special to "skip" their initialization!
joe
On Tue, 15 Feb 2005 17:45:09 -0800, "Rich" <Rich(a)discussions.microsoft.com> wrote:

>Hi guys,
>
>I am using listView on Dialog and need to refresh it with a button, the
>following is the code.
>
>void CMyList::OnBnClickedRun(int ix, float x)
>{
> CString str;
> m_myList.InsertColumn(0, "Name1", LVCFMT_LEFT, 100);
> m_myList.InsertColumn(1, "Name2", LVCFMT_LEFT, 100);
>
> m_myList.DeleteAllItems();
> LV_ITEM lvItem;
> lvItem.mask = LVIF_TEXT | LVIF_STATE;
> lvItem.state = 0;
> lvItem.stateMask = 0;
> str.Format(" %d", ix);
> m_myList.InsertItem(0, str);
> str.Format("%3.1f", x);
> m_myList.SetItemText(0, 1, str);
>
>}
>
>When I first click the refresh button, everything is alright. But when I
>click the button again, I always get a message
>
>The exception Breakpoint
>A breakpoint has been reached....
>
>When click cancel to debug it, I always get to here
>
>#undef _CrtDbgBreak
>
>_CRTIMP void _cdecl _CrtDbgBreak(
> void
> )
>{
> DebugBreak();
>}
>
>Any body has some idea what's wrong with my code? Many thanks!
>
>rich

Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm