I have a listview class. On a selection in the list I wand to call a listview that is another class.
I am having a problem doing this.
On selection of item in list a display list b.
On close of list b - return to same position in list a.
List a and list b are both standalone classes.
Help?
Could you be more specific with what your having a problem with? It's easy enough to show/hide a window (or control) with the ShowWindow method.
How to set it up.
I defined both classes and they work stand alone.
When I try to reference b from a the program crashes.
How are you giving one class a pointer to the other? Really hard when you make me guess (no code). ::)
The latest hacked up list class declarations.
// Stock Viewer Class
class StockView:Cdialog {
//overridden methods
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare OnNotify(int code,int nID,NMHDR *pnmhdr),int;
// class methods
const SV_CMD_OK = 1;
const SV_LISTVIEW_1 = 2;
const PV_LISTVIEW_1 = 3;
}
StockView::OnClose(),int {
CloseDialog(false);
return true;
}
StockView::OnInitDialog(),int {
CListView *StkList;
CListView *PrcList;
StkList = GetControl(SV_LISTVIEW_1);
PrcList = GetControl(PV_LISTVIEW_1);
if(StkList <> NULL) {
BldStkLst(StkList);
}
CenterWindow();
return true;
}
StockView::OnControl(int nID, int nNotifyCode, unsigned int hControl),int {
select nID {
case SV_LISTVIEW_1:
/* respond to control notifications here */
case SV_CMD_OK:
if(nNotifyCode = 0){
CloseDialog(true);
}
}
return true;
}
StockView::OnNotify(int code,int nID,NMHDR *pnmhdr),int {
CListView *sList = GetControl(SV_LISTVIEW_1);
CListView *pList = GetControl(PV_LISTVIEW_1);
CEdit *pEdit;
string sysbfr;
if(code = 0xFFFFFFFE){
if(nID = SV_LISTVIEW_1) {
sysbfr = sList->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList->DeleteAllItems();
pEdit = GetControl(GET_SYM);
pEdit->Clear();
ShowPrc(sysbfr,pList);
}
}
return true;
}
class PriceView:Cdialog {
//overridden methods
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
// class methods
const PV_CMD_OK = 1;
const PV_LISTVIEW_1 = 3;
}
PriceView::OnClose(),int {
CloseDialog(false);
return true;
}
PriceView::OnInitDialog(),int {
CListView *PrcList;
PrcList = GetControl(PV_LISTVIEW_1);
CenterWindow();
return true;
}
PriceView::OnControl(int nID, int nNotifyCode, unsigned int hControl),int {
select nID {
case PV_LISTVIEW_1:
/* respond to control notifications here */
case PV_CMD_OK:
if(nNotifyCode = 0){
CloseDialog(true);
}
}
return true;
}
Give me a clue to where it is crashing. Line number, run it through the debugger. Don't have the compiler in a workign state on my machine at the moment, in the middle of some changes.
Crashes in this code:
if(code = 0xFFFFFFFE){
if(nID = SV_LISTVIEW_1) {
sysbfr = sList->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList->DeleteAllItems();
pEdit = GetControl(GET_SYM);
pEdit->Clear();
ShowPrc(sysbfr,
I made some changes and this almost works.
// Stock Viewer Class
class StockView:Cdialog {
//overridden methods
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare OnNotify(int code,int nID,NMHDR *pnmhdr),int;
declare BldPrcLst(string sysbfr),int;
// class methods
const SV_CMD_OK = 1;
const SV_LISTVIEW_1 = 2;
const PV_CMD_OK = 3;
const PV_LISTVIEW_1 = 4;
}
StockView::OnClose(),int {
CloseDialog(false);
return true;
}
StockView::OnInitDialog(),int {
CListView *StkList;
CListView *PrcList;
StkList = GetControl(SV_LISTVIEW_1);
if(StkList <> NULL) {
BldStkLst(StkList);
}
CenterWindow();
return true;
}
StockView::OnControl(int nID, int nNotifyCode, unsigned int hControl),int {
select nID {
case SV_LISTVIEW_1:
/* respond to control notifications here */
case SV_CMD_OK:
if(nNotifyCode = 0){
CloseDialog(true);
}
}
return true;
}
StockView::OnNotify(int code,int nID,NMHDR *pnmhdr),int {
CListView *sList = GetControl(SV_LISTVIEW_1);
CListView *pList = GetControl(PV_LISTVIEW_1);
CEdit *pEdit;
string sysbfr;
if(code = 0xFFFFFFFE){
if(nID = SV_LISTVIEW_1) {
sysbfr = sList->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
// pList->DeleteAllItems();
// pEdit = GetControl(PV_CMD_OK);
// pEdit->Clear();
BldPrcLst(sysbfr);
}
}
return true;
}
class PriceView:Cdialog {
//overridden methods
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
// class methods
const PV_CMD_OK = 3;
const PV_LISTVIEW_1 = 4;
}
PriceView::OnClose(),int {
CloseDialog(false);
return true;
}
PriceView::OnInitDialog(),int {
CListView *PrcList;
PrcList = GetControl(PV_LISTVIEW_1);
CenterWindow();
return true;
}
PriceView::OnControl(int nID, int nNotifyCode, unsigned int hControl),int {
select nID {
case PV_LISTVIEW_1:
/* respond to control notifications here */
case PV_CMD_OK:
if(nNotifyCode = 0){
CloseDialog(true);
}
}
return true;
}
StockView::BldPrcLst(string sysbfr) {
CListView *PrcList;
unsigned int i,lodcnt;
lodcnt = 0;
i = 0;
PrcList->InsertColumn(0,"Symbol");
PrcList->InsertColumn(1," Date ");
PrcList->InsertColumn(2," Last Price ");
do {
if(Price[i].symbol = sysbfr) {
PrcList->InsertItem(lodcnt,Price[i].symbol);
PrcList->SetItemText(lodcnt,1,Price[i].date);
PrcList->SetItemText(lodcnt,2,NumToStr(Price[i].lstprc));
lodcnt++;
}
if(price[i].symbol = ""){
i = 500;
} else {
i++;
}
lodcnt++;
} until(i = 500);
if(lodcnt = 0){
messagebox(0,"No price user data for this stock","Price Data");
}
PrcList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
return;
}
It adds fields to the existing listview - I want a new listview window.
My guess is that an OnNotify is sent before one of the other controls is created.
if(code = 0xFFFFFFFE){
if(nID = SV_LISTVIEW_1) {
sysbfr = sList->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList->DeleteAllItems();
pEdit = GetControl(GET_SYM);
pEdit->Clear();
ShowPrc(sysbfr,
You should always check pointers for null before using them.
if(pList)
{
pList->DeleteAllItems();
}
Paul.
Never got it to work by having one list call another when an item was selected.
Got it to work by having 2 views in the same window.
Not what I wanted but it now works.
Still would like to find out how to select an item in a listview and have it open a new listview.
If anyone can do this please post an example here.