473,657 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<CCo mboBox*>

(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::GetDlgIte m()

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

Any suggestions will be appreciated.

Thanks

Manj.

Dec 4 '07 #1
8 1430
>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<CCo mboBox*>

(dlg.GetDlgIte m(IDC_COMBOExpI d));
}
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.G etString());

CComboBox* pCmbBox = static_cast<CCo mboBox*>(dlg.Ge tDlgItem(IDC_CO MBOExpId));
int i = pCmbBox->GetCurSel();
int n = pCmbBox->GetLBTextLen(i );
CString str;
pCmbBox->GetLBText(i,st r.GetBuffer(n)) ;
insCmd->Parameters["@expID"]->Value = gcnew String(str.GetS tring());
int rec = insCmd->ExecuteNonQuer y();
}
}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<CCo mboBox*>

(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<CCo mboBox*>(dlg.Ge tDlgItem(IDC_CO MBOExpId));
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.G etString());

CComboBox pCmbBox = static_cast<CCo mboBox>(dlg.m_e xpIdCmb);

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

error C2248: 'CObject::CObje ct' : 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.G etString());

CComboBox* pCmbBox = static_cast<CCo mboBox*>(dlg.Ge tDlgItem(IDC_CO MBOExpId));

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.G etString());

CComboBox* pCmbBox = static_cast<CCo mboBox*>(dlg.Ge tDlgItem(IDC_CO MBOExpId));

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<CCo mboBox>(dlg.m_e xpIdCmb);
>
where m_expIdCmb is the control variable added to the combo box. it is
giving the following error:

error C2248: 'CObject::CObje ct' : 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
3311
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 main form is reactivated following opening and closing a modal form. Strangely, this was not a problem until I started using my Access 2000 db in Access 2003 (as an Access 2000 db). Details follow... I have an unbound combo box on my main form...
5
1942
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 several options in each combo. In the first combo I want the user to be fit to select any of the options to allow the user to access the other two combo's, unless the user selects the option "Not Interested".
1
4147
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 box as a filter. In Access 2002 and earlier the row source for the second combo was "SELECT Field1, Field2 etc, FROM MyTable WHERE Field3 =
5
2238
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: ------------------------ // Fill the datasets for the combo boxes daDepartment.Fill(dsDepartment.Departments);
8
8247
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 company and has been flagged inactive. If you have a filter on the rowsource like Where Active = True then Joe's name would not show up in the combo list. This would be fine if the combo is associated with a field that is null/0. It would not be...
8
2197
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 Product where as the Row Source (See properties): SELECT tblProducts.ProductName, tblProducts.ProductName FROM tblProducts ORDER BY ProductName;
4
64587
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 determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
6
3674
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
7044
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 database I wrote for home, the combo boxes and listboxes no longer display the bound column. For example, on a form I have a combo box based on a table called 'names'. The two columns in the combo box are ID and Surname. The combo box and list box...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8723
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.