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