First in Roadview. CPP, initialize a List Control controls,
BOOL CRoadview: : OnInitDialog ()
{
CDialog: : OnInitDialog ();
CFont m_ListFont;
M_ListFont. CreatePointFont (120, "tahoma");
DWORD dwExStyle=m_listroad_view. GetExStyle ();
DwExStyle&=~ LVS_EX_CHECKBOXES;
M_listroad_view. SetFont (& amp; M_ListFont);
M_listroad_view. SetExtendedStyle (dwExStyle | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKA CTIVATE);
The TEXTMETRIC tm;
The CDC * pDC=GetDC ();
PDC - & gt; GetTextMetrics (& amp; Tm);
M_listroad_view. InsertColumn (0, "road number", LVCFMT_CENTER, 90, 0).
M_listroad_view. InsertColumn (1, "road" starting point, LVCFMT_CENTER, 160, 0).
M_listroad_view. InsertColumn (2, "section radius, LVCFMT_CENTER, 120, 0).
M_listroad_view. InsertColumn (3, "road length", LVCFMT_CENTER, 120, 0).
M_listroad_view. InsertColumn (4, "super" route, and LVCFMT_CENTER, 120, 0).
M_listroad_view. InsertColumn (5, "bending direction", LVCFMT_CENTER, 90, 0).
M_listroad_view. InsertColumn (6, "grade", LVCFMT_CENTER, 90, 0).
M_listroad_view. InsertColumn (7, "traffic", LVCFMT_CENTER, 120, 0).
M_listroad_view. InsertColumn (8, "design", LVCFMT_CENTER, 120, 0).
//TODO: Add extra initialization here
return TRUE;
}
The results shown in the figure below
My table is as follows:
Then add the read data code is as follows:
void CMHCSView: : OnRoadView ()compile right after implementation, the results are as follows:
{
COleVariant var.//the field type
Var. ChangeType (VT_BSTR, NULL);
CListCtrl m_listroad_view;
M_listroad_view. DeleteAllItems ();//to empty table
CDaoDatabase db.
CDaoRecordset RecSet (& amp; Db);
The Open (" data. MDB ");
RecSet. Open (AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM road", NULL);
Cstrings STR [9].
int i=0;
Int j=0;
while(! RecSet. IsEOF ())
{
RecSet. GetFieldValue (" ID ", var);
STR [0]=var. IntVal;
RecSet. GetFieldValue (" start ", var);
STR [1]=(LPCSTR) var. PbstrVal;
RecSet. GetFieldValue (" radius ", var);
STR [2]. The Format (" % 10.6 f ", var. DblVal);
RecSet. GetFieldValue (" length ", var);
STR [3]. The Format (" % 10.6 f ", var. DblVal);
RecSet. GetFieldValue (superelevation, var);
STR [4]. The Format (" % 10.6 f ", var. DblVal);
RecSet. GetFieldValue (" direction ", var);
STR [5]=var. IntVal;
RecSet. GetFieldValue (" grade ", var);
STR [6]. The Format (" % 10.6 f ", var. DblVal);
RecSet. GetFieldValue (" volume ", var);
STR [7]=var. IntVal;
RecSet. GetFieldValue (" velocity ", var);
STR [8]. The Format (" % d ", (LPCSTR) var. PbstrVal);
M_listroad_view. InsertItem (m_listroad_view. GetItemCount (), "");
for(j=0; j<=7. J++)
M_listroad_view. SetItemText (I, j, STR [j]);
I=I + 1;
RecSet. MoveNext ();
}
RecSet. Close ();
The Close ();
CRoadview rv;
The rv. DoModal ();
//TODO: Add your command handler code here
}
What's the problem???
CodePudding user response:
Good girl!Don't see any problems,
You need in OnRoadView ()/OnInitDialog (), respectively, to make a breakpoint, single step, see which place which statements would crash program?
In addition, OnRoadView () defines how m_listroad_view like global variable name? While it is possible, but not norm, easy to misunderstand,
M_ represents the member variables, you this is a local variable.
CodePudding user response:
Breakpoint debugging will not use this one, look not to understand ah,,,CodePudding user response: