Click to See Complete Forum and Search --> : Retrieving text from an MSDBGrid cell


TrimTrom
May 26th, 1999, 09:16 AM
Hello,

VC++ 6.0 Prof, Windows 98

I hope some one can help me. I have just used the MSDBGrid ActiveX
control for the first time in the following way:

I have created a AppWizard application with one splitter bar dividing
the window in two. In the top section I have put a CFormView dialog
with a DBGrid in it, and below, a CEdit View. What I want to do is
every time the user changes row in the DBGrid, the CEdit View displays
related information from the same database.

To do this, I have done the following in the FormView DBGrid class:

void CPTDBGView::OnRowColChangeDbgrid1(VARIANT FAR* LastRow, short
LastCol)
{
// TODO: Add your control notification handler code here
CMsDgridCtrl* ldgptr = (CMsDgridCtrl*) GetDlgItem(IDC_DBGRID1);
CString lstri;
lstri = ldgptr->GetColumns(1);
MessageBox(lstri,"Text");

}



The above must look very basic to experts; I have used the RowColChange
event, and in there I have attempted to load a key field from the row
(which has four columns, by the way) into a CString. The trouble is, I
do not know which command in the DBGrid control retrieves a cell's
text: I have attempted to use GetColumns, above, with no success, to
load the first column's text.

I would be very grateful if someone could show me the code to retrieve
text from a DBGrid column, and load it into a CString.

Sincerely,
Paul Trimming

----------------------------------
Email: paul.trimming_nospam@dial.pipex.com
4, High St, Merstham
Surrey RH1 3EA, England
----------------------------------

ric
May 26th, 1999, 11:19 AM
I have not worked with DBGrid ActiveX, but I think it's similar to CListCtrl so try GetItemText().

zhuang
June 30th, 1999, 10:55 PM
Have you solved your problem? I met the same problem. Could you put your solution, if any, on the site? Thanks.



Zenger Huang

RatherGolf
June 30th, 1999, 11:02 PM
Try using GetText() - this should return the text in the currently selected column.