Hi Anjali Devi,
Have you called EndEdit method of DataGridView before you retrieve the data from cell?
I have use the following sample to host DataGridView into MFC project.
http://www.codeproject.com/KB/miscctrl/mfcdialogwinforms.aspx
After I host it, I can use it just like in Winform CLR C++ project. In order to test the issue, I have created one column in DataGridView in OnInitDialog method.
BOOL CDGVMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
System::Windows::Forms::DataGridViewColumn^ dgvCol1 =
gcnew System::Windows::Forms::DataGridViewColumn(gcnew System::Windows::Forms::DataGridViewTextBoxCell());
dgvCol1->HeaderText = L"Column1";
dgvCol1->Name = L"Column1";
this->m_DataGridView1->Columns->Add(dgvCol1); return TRUE; // return TRUE unless you set the focus to a control
}
When I retrieve the data, I use the following code.
void CDGVMFCDlg::OnBnClickedBtngetdata()
{
this->m_DataGridView1->EndEdit(); System::String^ msg =
gcnew System::String(this->m_DataGridView1->Rows[m_DataGridView1->Rows->Count - 2]->Cells[m_DataGridView1->Columns->Count - 1]->Value->ToString());
System::Windows::Forms::MessageBox::Show(msg);
}
The last cell in DataGridView is the one I am editing, I can retrieve the value from it.
Hope this helps.
Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the
All-In-One Code Framework!