Thomas Stockbruegger
asked on
Need some help with Tabcontrol and Listcontrol
Hello,
I need some help to get data from a Tab Dialog.
My class CAngebot_Register_Kontroll e administered my tab/register.
In Angebot_Register_Kontrolle .cpp I did the following code:
#include "stdafx.h"
#include "Stockbruegger.h"
#include "Angebot_Register_Kontroll e.h"
#include ".\angebot_register_kontro lle.h"
//------------------------ ---------- ----
#include "Angebot_Dialog_Tab1.h"
#include "Angebot_Dialog_Tab2.h"
#include "Angebot_Dialog_Tab3.h"
#include "Angebot_Dialog_Tab4.h"
#include "Angebot_Dialog_Tab5.h"
//------------------------ ---------- ----
// CAngebot_Register_Kontroll e
IMPLEMENT_DYNAMIC(CAngebot _Register_ Kontrolle, CTabCtrl)
//-------------------- Konstruktor --------------------
CAngebot_Register_Kontroll e::CAngebo t_Register _Kontrolle ()
: m_tabCurrent(0)
, m_nNumberOfPages(0)
{
m_tabPages[0]=new CAngebot_Dialog_Tab1;
m_tabPages[1]=new CAngebot_Dialog_Tab2;
m_tabPages[2]=new CAngebot_Dialog_Tab3;
m_tabPages[3]=new CAngebot_Dialog_Tab4;
m_tabPages[4]=new CAngebot_Dialog_Tab5;
m_nNumberOfPages=5;
}
//------------------- Destruktor ----------------------
CAngebot_Register_Kontroll e::~CAngeb ot_Registe r_Kontroll e()
{
for(int nCount=0; nCount<m_nNumberOfPages; nCount++)
{
delete m_tabPages[nCount];
}
}
//------------------------ ---------- ---------- ----------
BEGIN_MESSAGE_MAP(CAngebot _Register_ Kontrolle, CTabCtrl)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
//######################## ## Funktion ########################## #########
void CAngebot_Register_Kontroll e::Registe rAuswahl()
{
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_ DIALOG_ANG EBOT_TAB1, this);
m_tabPages[1]->Create(IDD_ DIALOG_ANG EBOT_TAB2, this);
m_tabPages[2]->Create(IDD_ DIALOG_ANG EBOT_TAB3, this);
m_tabPages[3]->Create(IDD_ DIALOG_ANG EBOT_TAB4, this);
m_tabPages[4]->Create(IDD_ DIALOG_ANG EBOT_TAB5, this);
m_tabPages[0]->ShowWindow( SW_SHOW);
m_tabPages[1]->ShowWindow( SW_HIDE);
m_tabPages[2]->ShowWindow( SW_HIDE);
m_tabPages[3]->ShowWindow( SW_HIDE);
m_tabPages[4]->ShowWindow( SW_HIDE);
RegisterAufbau();// Funktion aufrufen
}
//######################## #### Funktion ########################## #########
void CAngebot_Register_Kontroll e::Registe rAufbau()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect .left-1;
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPo s(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
//------------------------ ---------- ---------- ---------- ---------- ---
for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
{
m_tabPages[nCount]->SetWin dowPos(&wn dTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
//------------------------ ---------- ---------- ---------- ---------
}
//######################## ########## ########## ########## ########## #####
I also did a function for every tab that the register has.
These functions I call from my Dialog Angebot_Dialog.cpp to get the data from each tab. In Angebot_Dialog I will get all the data for printing etc….
//######################## ########## ########## ########## ########## ########
void CAngebot_Register_Kontroll e::Hole_Da ten_von_Ta b5()
{
m_tabPages[4]->GetDlgItemT ext(IDC_ED IT_LIEFERZ EIT,str_Li eferzeit);
this works fine, I will get every data from each Editbox.
But I also want the data from a listview (Listcontrol)that is in Tab5
}
//######################## ########## ########## ########## ########## ########
// Angebot_Dialog.cpp : Implementierungsdatei
#include "stdafx.h"
#include "Stockbruegger.h"
#include "Angebot_Dialog.h"
#include ".\angebot_dialog.h"
//------------------------ ---------- --
#include "Angebot_Register_Kontroll e.h"
//------------------------ ---------- --
//######################## ########## ########## ########## #######
void CAngebot_Dialog::OnBnClick edButtonDr ucken()
{
//~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
m_myRegister.Hole_Daten_vo n_Tab5();
//~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
CString str_Lieferzeit;
str_Lieferzeit = m_myRegister.str_Lieferzei t;
here I get the data from the Editbox IDC_EDIT_LIEFERZEIT in Tab5
how get I access to the Listview in Tab5????
}
//######################## ########## ########## ########## #######
in
CAngebot_Dialog_Tab5.h
CListCtrl m_List;
So how do I get the data from my Listcontrol in Tab5 from Angebot_Dialog.cpp
Normal like this:
CString str_value;
str_value= m_List.GetItemText(Zeile,0 )
Thank you very much for your help.
500 points with a solution.
Best regards,
Thomas
P.S. still learing mfc
I need some help to get data from a Tab Dialog.
My class CAngebot_Register_Kontroll
In Angebot_Register_Kontrolle
#include "stdafx.h"
#include "Stockbruegger.h"
#include "Angebot_Register_Kontroll
#include ".\angebot_register_kontro
//------------------------
#include "Angebot_Dialog_Tab1.h"
#include "Angebot_Dialog_Tab2.h"
#include "Angebot_Dialog_Tab3.h"
#include "Angebot_Dialog_Tab4.h"
#include "Angebot_Dialog_Tab5.h"
//------------------------
// CAngebot_Register_Kontroll
IMPLEMENT_DYNAMIC(CAngebot
//-------------------- Konstruktor --------------------
CAngebot_Register_Kontroll
: m_tabCurrent(0)
, m_nNumberOfPages(0)
{
m_tabPages[0]=new CAngebot_Dialog_Tab1;
m_tabPages[1]=new CAngebot_Dialog_Tab2;
m_tabPages[2]=new CAngebot_Dialog_Tab3;
m_tabPages[3]=new CAngebot_Dialog_Tab4;
m_tabPages[4]=new CAngebot_Dialog_Tab5;
m_nNumberOfPages=5;
}
//------------------- Destruktor ----------------------
CAngebot_Register_Kontroll
{
for(int nCount=0; nCount<m_nNumberOfPages; nCount++)
{
delete m_tabPages[nCount];
}
}
//------------------------
BEGIN_MESSAGE_MAP(CAngebot
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
//########################
void CAngebot_Register_Kontroll
{
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_
m_tabPages[1]->Create(IDD_
m_tabPages[2]->Create(IDD_
m_tabPages[3]->Create(IDD_
m_tabPages[4]->Create(IDD_
m_tabPages[0]->ShowWindow(
m_tabPages[1]->ShowWindow(
m_tabPages[2]->ShowWindow(
m_tabPages[3]->ShowWindow(
m_tabPages[4]->ShowWindow(
RegisterAufbau();// Funktion aufrufen
}
//########################
void CAngebot_Register_Kontroll
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPo
//------------------------
for(int nCount=1; nCount < m_nNumberOfPages; nCount++)
{
m_tabPages[nCount]->SetWin
}
//------------------------
}
//########################
I also did a function for every tab that the register has.
These functions I call from my Dialog Angebot_Dialog.cpp to get the data from each tab. In Angebot_Dialog I will get all the data for printing etc….
//########################
void CAngebot_Register_Kontroll
{
m_tabPages[4]->GetDlgItemT
this works fine, I will get every data from each Editbox.
But I also want the data from a listview (Listcontrol)that is in Tab5
}
//########################
// Angebot_Dialog.cpp : Implementierungsdatei
#include "stdafx.h"
#include "Stockbruegger.h"
#include "Angebot_Dialog.h"
#include ".\angebot_dialog.h"
//------------------------
#include "Angebot_Register_Kontroll
//------------------------
//########################
void CAngebot_Dialog::OnBnClick
{
//~~~~~~~~~~~~~~~~~~~~~~~~
m_myRegister.Hole_Daten_vo
//~~~~~~~~~~~~~~~~~~~~~~~~
CString str_Lieferzeit;
str_Lieferzeit = m_myRegister.str_Lieferzei
here I get the data from the Editbox IDC_EDIT_LIEFERZEIT in Tab5
how get I access to the Listview in Tab5????
}
//########################
in
CAngebot_Dialog_Tab5.h
CListCtrl m_List;
So how do I get the data from my Listcontrol in Tab5 from Angebot_Dialog.cpp
Normal like this:
CString str_value;
str_value= m_List.GetItemText(Zeile,0
Thank you very much for your help.
500 points with a solution.
Best regards,
Thomas
P.S. still learing mfc
Hi tsp2002,
there IMO are two easy ways:
1. casting the dialog and accessing the data directly, i.e.:
2. Using GetDlgItem:
With both ways you should verify pList != NULL before you use it.
Hope that helps,
ZOPPO
there IMO are two easy ways:
1. casting the dialog and accessing the data directly, i.e.:
CListCtrl* pList = &((CAngebot_Dialog_Tab5*)m_tabPages[4])->m_List;
2. Using GetDlgItem:
CListCtrl* pList = (CListCtrl*)m_tabPages[4]->GetDlgItem(IDC_LIST);
With both ways you should verify pList != NULL before you use it.
Hope that helps,
ZOPPO
ASKER
Hi Andy,
that will not work:
Angebot_Register_Kontrolle .cpp
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \MultiColu mnComboBox .h(51) : warning C4311: 'Typumwandlung': Zeigerverkürzung von 'WNDPROC' zu 'long'
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \MultiColu mnComboBox .h(51) : warning C4312: 'Typumwandlung': Konvertierung von 'LONG' in größeren Typ 'WNDPROC'
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \MultiColu mnComboBox .h(56) : warning C4311: 'Typumwandlung': Zeigerverkürzung von 'WNDPROC' zu 'long'
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \Angebot_R egister_Ko ntrolle.cp p(344) : error C2039: 'm_List': Ist kein Element von 'CDialog'
c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\af xwin.h(276 7): Siehe Deklaration von 'CDialog'
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \Angebot_R egister_Ko ntrolle.cp p(344) : error C2228: Der linke Teil von '.GetItemText' muss eine Klasse/Struktur/Union sein
Das Build-Protokoll wurde unter "file://d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL \Debug\Bui ldLog.htm" gespeichert.
Stockbruegger - 2 Fehler, 3 Warnung(en)--------------- ---------- --
that will not work:
Angebot_Register_Kontrolle
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\af
d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
Das Build-Protokoll wurde unter "file://d:\Eigene Dateien\Visual Studio Projects\Stockbruegger-SQL
Stockbruegger - 2 Fehler, 3 Warnung(en)---------------
ASKER
Hi Zoppo,
do you mean the location here?
how do I get now the data from Angebot_Dialog.cpp
void CAngebot_Register_Kontroll e::Hole_Daten_von_Tab5()
{
CListCtrl* pList =(CListCtrl*)m_tabPages[4] ->GetDlgIt em(IDC_LIS T1);
}
do you mean the location here?
how do I get now the data from Angebot_Dialog.cpp
void CAngebot_Register_Kontroll
{
CListCtrl* pList =(CListCtrl*)m_tabPages[4]
}
Then you need to cast the page to the expected type of dialog - see the code from Zoppo
eg.
CString str_value;
str_value= ((CAngebot_Dialog_Tab5*)m_ tabPages[5 ])->m_List .GetItemTe xt(Zeile,0 );
ps. If you are wanting to getting multiple values / perform multiple actions on the ListControl then casting to a pList pointer as Zoppo suggests will be an advantage.
eg.
CString str_value;
str_value= ((CAngebot_Dialog_Tab5*)m_
ps. If you are wanting to getting multiple values / perform multiple actions on the ListControl then casting to a pList pointer as Zoppo suggests will be an advantage.
Yes, that's what I meant ...
BTW, to make it a bit more safe and if you want to profit from MFC's debugging helpers you should use STATIC_DOWNCAST - this throws an ASSERT in DEBUG build in case the passed pointer is NULL or the pointed object is not of the expected type - it's even easy but may help finding problems somewhen:
BTW, to make it a bit more safe and if you want to profit from MFC's debugging helpers you should use STATIC_DOWNCAST - this throws an ASSERT in DEBUG build in case the passed pointer is NULL or the pointed object is not of the expected type - it's even easy but may help finding problems somewhen:
CListCtrl* pList = STATIC_DOWNCAST( CListCtrl, m_tabPages[4]->GetDlgItem( IDC_LIST1 ) );
if ( NULL == pList )
{
return;
}
CString strValue = pList->GetItemText( ... );
ZOPPO
ASKER
okay Zoppo, that works..... but how do I get the value from strValue in CAngebot_Dialog
void CAngebot_Dialog::OnBnClick edButtonDr ucken()
{
//~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
m_myRegister.Hole_Daten_vo n_Tab5();
//~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
CListCtrl* pList = STATIC_DOWNCAST( CListCtrl, m_tabPages[4]->GetDlgItem( IDC_LIST1 ) );
if ( NULL == pList )
{
return;
}
CString strValue = pList->GetItemText( ... );
void CAngebot_Dialog::OnBnClick
{
//~~~~~~~~~~~~~~~~~~~~~~~~
m_myRegister.Hole_Daten_vo
//~~~~~~~~~~~~~~~~~~~~~~~~
CListCtrl* pList = STATIC_DOWNCAST( CListCtrl, m_tabPages[4]->GetDlgItem(
if ( NULL == pList )
{
return;
}
CString strValue = pList->GetItemText( ... );
ASKER
forget the last question....it is morning...i was not thinking...it works
ASKER
Hi Zoppo,
the only last question:
in my Listcontorl are multiple rows and columns.
Should I use an array to store all the data in CAngebot_Register_Kontroll e::Hole_Da ten_von_Ta b5()?
and read that array form CAngebot_Dialog?
the only last question:
in my Listcontorl are multiple rows and columns.
Should I use an array to store all the data in CAngebot_Register_Kontroll
and read that array form CAngebot_Dialog?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you for your help, that was even better.
Have a great day.
Best regards from Thomas
Have a great day.
Best regards from Thomas
You're welcome, I'm glad I could help,
have a nice day too,
best regards,
ZOPPO
have a nice day too,
best regards,
ZOPPO
you should consider to getting the data from CAngebot_Register_Kontroll e rather than from the screen of a special tab.
the CAngebot_Register_Kontroll e should have members for all the fields of all tabs. it also should have an array (for example a std::vector) where you hold the data for each row of the list control in tab 5. to get the members filled you would add a function for each tab dialog where you either would get the data from screen and fill the members of CAngebot_Register_Kontroll e or where you set the screen values from members of CAngebot_Register_Kontroll e
when a tab page was changed you call the exchange function with bToScreen = false. so the data of all tabs not currently active were always saved to register.
if you do so for all tabs, you always can get the current data from register rather than from the screen of the not visible tabs.
Sara
the CAngebot_Register_Kontroll
bool CAngebot_Dialog_Tab5::ScreenMemberExchange(bool bToScreen)
{
CListCtrl * pList = ((CListCtrl *)GetDlgItem(IDC_LIST);
if (bToScreen == false)
{
// get data from screen
GetDlgItem(IDC_EDIT_LIEFERZEIT)->GetWindowText(m_myRegister. str_Lieferzeit);
...
int num = pList->GetItemCount();
m_myRegister.m_dataArray.clear(); // make array empty
for (int n = 0; n < num; ++n)
{
m_myRegister.m_dataArray.push_back(CRowData());
CRowData & row = m_myRegister.m_dataArray.last();
row.m_strFirstColumn = pList->GetItemText(n, 0);
row.m_strSecondColumn = pList->GetItemText(n, 1);
....
}
}
else /*if (bToScreen == true)*/
{
// set data from register to screen
GetDlgItem(IDC_EDIT_LIEFERZEIT)->SetWindowText(m_myRegister. str_Lieferzeit);
...
int num = (int)m_myRegister.m_dataArray.size();
pList->DeleteAllItems(); // make list empty
for (int n = 0; n < num; ++n)
{
CRowData & row = m_myRegister.m_dataArray[n];
pList->InsertItem(n, row.m_strFirstColumn);
pList->SetItemText(n, 1, row.m_strSecondColumn);
....
}
}
return true;
}
when a tab page was changed you call the exchange function with bToScreen = false. so the data of all tabs not currently active were always saved to register.
if you do so for all tabs, you always can get the current data from register rather than from the screen of the not visible tabs.
Sara
Open in new window