473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Combo Box access

Hi

I am trying to access a combobox of a dialogbox. The code is someting like
that:
void CDatabaseView::OnAddExpdata()
{
CExpDataDlg dlg;
CComboBox* pCmbBox = static_cast<CComboBox*>

(dlg.GetDlgItem(IDC_COMBOExpId));
}

where IDC_COMBOExpId is a combobox in the dialogbox dlg (CExpDataDlg).

The problem is that it is throwing following exception in CWND::GetDlgItem()

"There is no source code available for the current location."

Any suggestions will be appreciated.

Thanks

Manj.

Dec 4 '07 #1
8 1416
>I am trying to access a combobox of a dialogbox. The code is someting like
>that:
void CDatabaseView::OnAddExpdata()
{
CExpDataDlg dlg;
CComboBox* pCmbBox = static_cast<CComboBox*>

(dlg.GetDlgItem(IDC_COMBOExpId));
}
Presumably you're a bit lost in what you're doing?

I'd guess that you've been told to add some extra functionality to
someone else's application?

Since the (Windows) dialog has not been created at that point, there
is no combo box to get. Although the dialog class instance exists, a
visible dialog (with child controls) doesn't exist until you've called
DoModal (for a modal dialog) or Create (for a modeless dialog).

Is this an existing dialog box?
Is it a modeless one, or a modal one?
What's the relationship between your view class and the dialog?

Dave
Dec 4 '07 #2
Hi Dave

Thanks for your reply. Actually to shorten the code I deleted the lines in
between. Please accept my apologies. The actual code is:

void CDatabaseView::OnAddExpdata()
{

CExpDataDlg dlg;
INT_PTR nRet = -1;
nRet = dlg.DoModal();
do{
if (nRet == IDOK){
CWaitCursor wc;
//Assign values to the parameters
insCmd->Parameters["@dataID"]->Value = gcnew String
(dlg.m_DataID.GetString());

CComboBox* pCmbBox = static_cast<CComboBox*>(dlg.GetDlgItem(IDC_COMBOEx pId));
int i = pCmbBox->GetCurSel();
int n = pCmbBox->GetLBTextLen(i);
CString str;
pCmbBox->GetLBText(i,str.GetBuffer(n));
insCmd->Parameters["@expID"]->Value = gcnew String(str.GetString());
int rec = insCmd->ExecuteNonQuery();
}
}while(nRet == IDOK);
}

As I am calling GetDlgItem() after dlg.DoModal() The dilogbox do exist. But
it is still giving the same exception.

I am trying to populate the database (expData table) using the dialogbox
(CExpDataDlg) as instantiated above in the OnAddExpdata() function of the
view class. If I am not using the Combo box it works fine.

Cheers.

Manjree
"David Lowndes" wrote:
I am trying to access a combobox of a dialogbox. The code is someting like
that:
void CDatabaseView::OnAddExpdata()
{
CExpDataDlg dlg;
CComboBox* pCmbBox = static_cast<CComboBox*>

(dlg.GetDlgItem(IDC_COMBOExpId));
}

Presumably you're a bit lost in what you're doing?

I'd guess that you've been told to add some extra functionality to
someone else's application?

Since the (Windows) dialog has not been created at that point, there
is no combo box to get. Although the dialog class instance exists, a
visible dialog (with child controls) doesn't exist until you've called
DoModal (for a modal dialog) or Create (for a modeless dialog).

Is this an existing dialog box?
Is it a modeless one, or a modal one?
What's the relationship between your view class and the dialog?

Dave
Dec 4 '07 #3
Thanks for your reply. Actually to shorten the code I deleted the lines in
>between. Please accept my apologies. The actual code is:

void CDatabaseView::OnAddExpdata()
{

CExpDataDlg dlg;
INT_PTR nRet = -1;
nRet = dlg.DoModal();
do{
if (nRet == IDOK){
CWaitCursor wc;
//Assign values to the parameters
insCmd->Parameters["@dataID"]->Value = gcnew String
(dlg.m_DataID.GetString());

CComboBox* pCmbBox = static_cast<CComboBox*>(dlg.GetDlgItem(IDC_COMBOEx pId));
By the time your dialog has exited DoModal, the child controls no
longer exist.

The neatest solution is to use MFCs DDX mechanism to copy the dialog
control data to public member variables of your dialog class - that
way they'll still exist after the dialog has been closed.

Dave
Dec 4 '07 #4
Hi Dave

Thanks or the reply. I've tried using the member control variable like:

void CDatabaseView::OnAddExpdata()
{

CExpDataDlg dlg;
INT_PTR nRet = -1;
nRet = dlg.DoModal();
do{
if (nRet == IDOK){
CWaitCursor wc;
//Assign values to the parameters
insCmd->Parameters["@dataID"]->Value = gcnew String
(dlg.m_DataID.GetString());

CComboBox pCmbBox = static_cast<CComboBox>(dlg.m_expIdCmb);

where m_expIdCmb is the control variable added to the combo box. it is
giving the following error:

error C2248: 'CObject::CObject' : cannot access private member declared in
class 'CObject'
I don't get why the Dialog box is exited at this point? It is still there as
I am entering the values in different fields.

Cheers

Manjree
"David Lowndes" wrote:
Thanks for your reply. Actually to shorten the code I deleted the lines in
between. Please accept my apologies. The actual code is:

void CDatabaseView::OnAddExpdata()
{

CExpDataDlg dlg;
INT_PTR nRet = -1;
nRet = dlg.DoModal();
do{
if (nRet == IDOK){
CWaitCursor wc;
//Assign values to the parameters
insCmd->Parameters["@dataID"]->Value = gcnew String
(dlg.m_DataID.GetString());

CComboBox* pCmbBox = static_cast<CComboBox*>(dlg.GetDlgItem(IDC_COMBOEx pId));

By the time your dialog has exited DoModal, the child controls no
longer exist.

The neatest solution is to use MFCs DDX mechanism to copy the dialog
control data to public member variables of your dialog class - that
way they'll still exist after the dialog has been closed.

Dave
Dec 4 '07 #5
Just to add to my previous reply m_expIdCmb is declared public as follows in
the CExpDataDlg class:
public:
CComboBox m_expIdCmb;

"David Lowndes" wrote:
Thanks for your reply. Actually to shorten the code I deleted the lines in
between. Please accept my apologies. The actual code is:

void CDatabaseView::OnAddExpdata()
{

CExpDataDlg dlg;
INT_PTR nRet = -1;
nRet = dlg.DoModal();
do{
if (nRet == IDOK){
CWaitCursor wc;
//Assign values to the parameters
insCmd->Parameters["@dataID"]->Value = gcnew String
(dlg.m_DataID.GetString());

CComboBox* pCmbBox = static_cast<CComboBox*>(dlg.GetDlgItem(IDC_COMBOEx pId));

By the time your dialog has exited DoModal, the child controls no
longer exist.

The neatest solution is to use MFCs DDX mechanism to copy the dialog
control data to public member variables of your dialog class - that
way they'll still exist after the dialog has been closed.

Dave
Dec 4 '07 #6
>Just to add to my previous reply m_expIdCmb is declared public as follows in
>the CExpDataDlg class:
public:
CComboBox m_expIdCmb;
Regardless, it won't work.

Although the C++ object wrappers exist after DoModal has returned, the
underlying Windows controls don't - you have to copy any data from the
controls into public data variables (not control variables) so they
persist past the lifetime of the Windows dialog box.

If you're not aware of these issues, have a work through the Scribble
sample - that will teach you the DDX fundamentals.

Dave
Dec 4 '07 #7
Thanks Dave. I was in the impression that adding a simple data variable with
combo box won't work though I was using the same method accessing edid box's
values. It worked.

Thanks again.

Manj.

"David Lowndes" wrote:
Just to add to my previous reply m_expIdCmb is declared public as follows in
the CExpDataDlg class:
public:
CComboBox m_expIdCmb;

Regardless, it won't work.

Although the C++ object wrappers exist after DoModal has returned, the
underlying Windows controls don't - you have to copy any data from the
controls into public data variables (not control variables) so they
persist past the lifetime of the Windows dialog box.

If you're not aware of these issues, have a work through the Scribble
sample - that will teach you the DDX fundamentals.

Dave
Dec 4 '07 #8
CComboBox pCmbBox = static_cast<CComboBox>(dlg.m_expIdCmb);
>
where m_expIdCmb is the control variable added to the combo box. it is
giving the following error:

error C2248: 'CObject::CObject' : cannot access private member declared in
class 'CObject'
You can't copy a CComboBox into a local variable that way, use a pointer or
reference instead.
Dec 4 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: will eichert | last post by:
Greetings. I have a problem with a combo box incorrectly displaying blank items when returning to a form from a modal form. It's fine when the main form first comes up, but gets messed up when the...
5
by: Cillies | last post by:
Hi all, I have three combo boxes on a form! what I want to be able to do is manipulate access to the last two combos, depending on the selection of the options in the first combo. I have...
1
by: Jeff Smith | last post by:
Hi This is a repost due to no responses Here's a problem I've encountered with Access 2003 which has got me to redesign how I get the row source in a second combo box using the first combo...
5
by: Ant | last post by:
Hi, (Winform VS2003) I have a combo box bound to a typed data set. When the form loads, the combo box is popluated using a method containing the simple code below: ------------------------...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
8
by: AA Arens | last post by:
Hi I do have a products table and products-parts table in my Access 2003 database and log all services into a form. I do have at least the following two combo boxes on my form: - Choose...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
2
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.