Home » Category » Microsoft Visual C & C++

Microsoft Visual C & C++: Document Adding Items to List Control

202| Wed, 06 Feb 2008 18:15:00 GMT| jeffking| Comments (7)
I am trying to update my List Control and add items through my document to my View. Here's what I have:

CMoneyManagerView *ptr = (CMoneyManagerView*)AfxGetMainWnd();
ptr->UpdateWindow();
ptr->GetListCtrl().InsertItem(0,"TEST");
UpdateAllViews(NULL);

I can't seem to figure out how to insert the item correctly, the above code just doesn't do anything. Got any ideas?

Keywords & Tags: document, adding, items, list, control, microsoft, visual c++, vc

URL: http://www.7prog.com/visual-c-c++/95054/
 
«« Prev - Next »» 7 helpful answers below.
AfxGetMainWnd() return pointer to the Mainframe Window object, not to the view window. Your first line is absolutely wrong. Use another method

Rating isn't important...But gurus respect it and keep high

igbrus | Sat, 10 Nov 2007 06:01:00 GMT |

What method should I use? How do I update the list control on my one view?

Is it possible? I know you can use GetDocument() to return a pointer to the document in the view, how do I go viceversa?

Thanks
Jeff

jeffking | Sat, 10 Nov 2007 06:02:00 GMT |

1. You can enumerate all views of the document via GetFirstViewPosition, GetNextView
2. If you already in view, why you need pointer to view or it's another view?

Rating isn't important...But gurus respect it and keep high

igbrus | Sat, 10 Nov 2007 06:03:00 GMT |

1) How do I use GetFirstViewPosition? Will that return a pointer to that view? How does it know that its the view I want? Do you have any code for that?

2) That function is in the document, I would of had it in the view (which would of eliminated this whole problem) but if its in the view then it would be disabled if the user clicked in the other view. So I put it in the document to enable it on both views.

Thanks
Jeff

jeffking | Sat, 10 Nov 2007 06:04:00 GMT |

I suggest the folowing options:
1. GetNextView enumerate in the sequence of creation. So you can know which is ListView
2. You can use GetRuntimeClass or typeid or dynamic_cast
3. You can Send some message for every view and process the message just for ListView

POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CMyView* pView = GetNextView(pos);
::SendMessage(pView->GetSafeHwnd,....);
}



Rating isn't important...But gurus respect it and keep high

igbrus | Sat, 10 Nov 2007 06:05:00 GMT |

Ok,

I understand but I can't seem to get it to work. Here's what I have:

void CRetDoc::OnButton32771()
{
// TODO: Add your command handler code here
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CRetView* pView = (CRetView*)GetNextView(pos);
::SendMessage(pView->GetSafeHwnd,pView->GetListCtrl().InsertItem(0,"sdf"));


}
}

It says Send Message does not take 2 parameters, but What message would I send? is it correct?

Thanks
Jeff

jeffking | Sat, 10 Nov 2007 06:06:00 GMT |

Please, look at the VC++ help into ::SendMessage. You have to send four parameters. You interpret my answers too directly. If you can't to solve the problem, send me zipped project to my mail

Rating isn't important...But gurus respect it and keep high

igbrus | Sat, 10 Nov 2007 06:07:00 GMT |

Microsoft Visual C & C++ Hot Answers

Microsoft Visual C & C++ New questions

Microsoft Visual C & C++ Related Categories